Learning Glassblowing

I recently took a series of three intro to glassblowing courses at Revere Glass in Berkeley, California. Our teachers were very helpful, the workshop itself well stocked with tools, and the glass was plentiful. The fish sculpture below is the output of my third course.

Glassblowing has proved to be an interesting combination of art and science. We'd seen its master craftsmen at work in Venice and shaping glowing, flowing, 1000C hot glass proved as challenging and fun as I'd imagined. You can let your creativity loose yet still have to respect and be conscious of the physical properties of glass. The difference between cold and hot seals, flashing your piece to prevent cracking, constantly rotating the glass to maintain control over it, how to work "frit" or colors into your piece, and much more.

All in all it was a great experience and, if you're in the Bay Area, I highly recommend Revere Glass (watch out for their Groupon offers).

Mount Diablo Tarantulas

As I was biking up Mount Diablo the other day, I came across an animal I'd been keeping an eye out for: a male tarantula in wanderlust. They're easiest to spot as they cross the road, and this one was quite determined to get to the other side.

In the fall the male tarantulas set off in search of females to mate with. If she doesn't eat him (which she'll only do if she's famished) he'll keep looking for partners until the cold weather, or a hungry lover, gets him. Females, on the other hand, can live up to twenty years.

I've always liked spiders but this one was wary of me and wouldn't stay on my hand. That's OK :-)

This article has more information about these fascinating creatures.

World Population by Time Zone

Cory Doctorow, scifi author and BoingBoing co-founder, once wrote a scifi novel called Eastern Standard Tribe (available free). It was fun read but what I enjoyed most was his idea that people would belong to a "tribe" based on their time zone. In Doctorow's world, your loyalties lie not with the country of your birth but with the people who are up when you are.

This evening I was thinking about this novel and idly wondered which tribe would be the biggest? In other words, which time zone is the most highly populated?

Looking at a map, the answer was obvious: it had to be UTC+8 which includes not only China but Malaysia, the Philippines, and more.

Still, the fun of such a frivolous question is less in the answer than in the answering, so I fired up Mathematica and a few calculations later generated this graph.

I cheated a little by using a simplifying assumption: if a country has multiple time zones, I divide its population evenly between them. This inaccuracy doesn't change the fact that our top three are... <drumroll>
  1. UTC+8: China and others
  2. UTC+5.5: India and others
  3. UTC+1: Western Europe and a good chunk of Africa

According to Mathematica, there are 39 different time zones ranging from UTC-11.5 to UTC+14. I wonder if anyone has visited them all? Now that would be a glorious adventure! :-)

Fearless Fire Eating at The Crucible

My 12 year old son Thomas and I took a three hour fire eating course yesterday in downtown Oakland at The Crucible. We found it through the excellent Workshop Weekend program, which offers many interesting courses. We were the only two students and our teacher, Patricia, gave us a great introduction to both the art and science of fire eating

Warning: fire eating is dangerous and an easy way to get hurt quickly. The information below is no substitute for proper instruction (it's incomplete too!). In other words... Don't do this at home!

After a comprehensive review of safety precautions, Patricia taught us how to make our own torches. These consisted of 18" aluminum rods with a wick at one end. Interestingly, the wick is made of a 12" long strip of kevlar and held in place by kevlar string. Kevlar has high heat resistance and is reasonably absorbent so it makes for a great wick. 

For our initial foray into fire eating, we used rubbing alcohol as fuel because the flame is small. Maybe so but we were still more than a little apprehensive about putting a flaming torch in our mouths!

After the first try it became a lot easier and we soon graduated to white (camping) gas which generates much bigger and brighter flames, as the pictures below show. We quickly conquered any fears we had and became pretty comfortable eating fire.

The science behind this art wasn't what I'd expected. I'd assumed that fire eating consisted of closing your mouth around the flaming torch to deprive it of oxygen and so stop it burning. Not so. You never fully close your mouth around the torch (burnt lips anyone?) instead you close them partially and exhale to extinguish the flame.

Once our basic skills were in place we moved on to art. Patricia taught us various tricks such as flame transfers and ways to light the torches. She was particularly impressed by Thomas who, in the six years she's been teaching the class, was by far her youngest student.

All in all it was indeed a glorious adventure and one we're going to practice ourselves, safely.

 

Visualizing One Hundred Years of Pacific Rim Earthquakes

Whenever I hear of a major earthquake, I always wonder when our turn will come. I've been asking myself that question way too frequently recently. My family and I live in the San Francisco Bay Area, prime earthquake country (or so I thought until I looked at Japan...). I started playing with NOAA's earthquake data after the New Zealand earthquake. After the recent Japan quake, I thought I'd publish a few graphics. 

Disclaimer: I'm no geologist, statistician, or expert on earthquakes. I don't even play one on TV. I don't think anyone can predict earthquakes with any certainty (though there is some interesting research) and I certainly won't try.

The Ring of Fire is the name given to the chain of mountains, volcanoes, and faults that ring the Pacific Ocean. Of the world's 16 largest earthquakes since 1900, 15 occurred in the Ring of Fire.

Here's an interesting graphic showing the earthquakes above 6.0 magnitude that have hit the Ring of Fire region since 1900. Earthquakes of magnitudes between 6 and 7 are in green, between 7 and 8 in blue, and 8 or higher in red.

Notice anything? Well, as a Californian, the first thing that struck me was: "we're getting off lightly!".

This movie gives you a different way to see the earthquakes. Same legend as before: magnitude 6+ green, 7+ blue, 8+ red. The video isn't the most exciting one you'll ever see. It helps to pick a point of interest on the map and imagine some elevator music in the background :-)

Let's dig deeper...

Japan, California, New Zealand, and Chile

Looking at the graph above it's clear California gets fewer earthquakes than many other parts of the Ring.

When I compare a circular area 2,000km around the center of Japan with the same size area around California (centered on San Francisco), Japan has been hit four times as often by large (i.e. 6+ magnitude) earthquakes than California (~200 vs. ~50).

Here are Japan's large earthquakes, with 6.x, 7.x, and 8+ magnitude earthquakes broken out (notice that the data for 6.x earthquakes in 1900-1950 is likely incomplete):

The equivalent map for the 2,000 km surrounding San Francisco looks like this (sorry, no, there are no 8+ earthquakes, NOAA has the 1906 one at 7.9):

Let's look at the "earthquake history" in the other recent hotspots: New Zealand and Chile.

Earthquakes from 1900-2011 in a 2,000km area centered on Christchurch, New Zealand.

And finally South America. 2,000km area centered on Santiago, Chile. (That 9.5'er in 1960 was a monster). 

BTW, I've only focused on a few of the Ring of Fire hotspots. Indonesia, Central America, etc. are all very active.

So are we Californians due for an earthquake?

As I wrote earlier: Who really knows? On the one hand 110 years of data tells us that our corner of the Ring of Fire experiences 25% as many earthquakes as Japan. On the other hand... It may be about time for a big one to hit us.

Simon Winchester (an author whose many books I'd recommend, esp. The Man Who Loved Chinawrote recently:

[The Chile, New Zealand, and Japan earthquakes]  involved more or less the same family of circum-Pacific fault lines and plate boundaries—and though there is still no hard scientific evidence to explain why, there is little doubt now that earthquakes do tend to occur in clusters: a significant event on one side of a major tectonic plate is often—not invariably, but often enough to be noticeable—followed some weeks or months later by another on the plate’s far side. [...]

Now there have been catastrophic events at three corners of the Pacific Plate—one in the northwest, on Friday; one in the southwest, last month; one in the southeast, last year.

That leaves just one corner unaffected—the northeast.

Are earthquakes really clustered? I haven't analyzed the data for correlations. Just eyeballing the graphs above, there are enough earthquakes happening around the Pacific Rim that you could claim some correlation exists.

If you want my advice... Better safe than sorry: Be prepared.

Technical Info

All graphs were created with Mathematica 8, one of my favorite pieces of software. It's a tremendously powerful package and, though it does have a bit of a learning curve, the help system is excellent at giving lots of examples.

There's a lot more that could, and probably should, be done with this data: time-based analysis, looking for correlations, leveraging more of the data (e.g. tsunamis, impact of earthquakes, etc.).

The graphs above are pretty simple. Mathematica can create much more sophisticated ones. Here's 3D version of the Japan-area earthquakes.

 

A Puzzle To Die For

Came across this very cool puzzle at Brisbane's Museum of Science: they'd cut a die into nine pieces and it was up to you to put it back together. Being a big fan of polyhedra the puzzle instantly appealed to me, but I also like the fact that it forced people to think of how a die is constructed. For example, which faces are opposite which? Given there were only nine pieces it wasn't hard putting it back together again but Katrine and I had fun solving the puzzle nonetheless.

Mathematica, Pi, Mandelbrot, OpenCL, and More

As usual I was looking for something completely different (pages devoted to the game Hex, but that's another story) and came across this intriguing finding by Dave Brol.

Dave was investigating whether the "neck" of the Mandelbrot set was infinitely thin, and in the process realized that pi was showing up in the number of iterations he was performing. What the?!

Curious, I whipped up a quick Mathematica function to test his observation (and as another excuse to play with Mathematica :-)

First I define Mandelbrot's function, here called mandelIter. Nice, I can actually use complex numbers in Mathematica. This function is usually written to include a stopping condition based on a max number of iterations. I chose to omit it here since the points we're investigating are supposed to eventually escape the set.

The point in question is (-0.75 + x i) where x -> 0. The table shows what occurs for ever more "precise" (i.e. closer to 0) values of x. The right hand column lists pairs of numbers. The left one is the time it took to execute mandelIter in seconds. The right one is the number of iterations before escaping the set.

Notice anything special regarding those iteration counts? Yup, we're re-discovering pi.

The other thing you may have noticed is that it's going to take a long long time to calculate pi this way. Each subsequent finding takes 10 times longer to compute.

Naturally, I wondered how to make mandelIter faster.

Mathematica includes a Compile[] function, which basically turns a function into an optimized version, though it's still in pcode, not machine code.

My first attempt was just to compile the Abs[] and z = z^2 + c functions, but this resulted in trivial speed improvements. The solution was to let Mathematica compile the whole function.

Much faster! Unfortunately, it runs into problems and never returns when I go to 10^-8:

My assumption is that compilation uses machine-level precision instead of the arbitrary precision that's Mathematica's default. Since we're squaring very small numbers, we're rapidly exceeding this precision. It's pretty cool that Mathematica realizes this and switches back.

Still, I was hoping for more.

One of the features new to Mathematica 8 is the ability to leverage your computer's GPU, i.e. your graphics processor. Modern graphics chips actually have a massive amount of computing power and are highly parallelized. You typically program these chips with either CUDA (which is NVidia specific) or OpenCL (an industry standard). As of Snow Leopard, Apple includes OpenCL drivers with its Macs.

Re-implementing the algorithm was pretty easy: you're writing C code with an OpenCL flavor. Previous versions calculated each row sequentially. This version calculates them in parallel. After all, there are 48 (!) cores on my laptop's GPU :-)

mandelCLsrc takes 5 arguments: two input vectors, one output vector, the length of the vectors, and the max iterations we want to compute. Then I compile it with OpenCLFunctionLoad[]. Notice the "8" parameter: that means we want to leverage 8 cores to process this function.

If you're doing any OpenCL programming, definitely use OpenCLFunctionLoad[]'s ShellOutputFunction -> Print option, it'll help you find errors. While I'm on the subject: if Mathematica stops compiling OpenCL functions or behaves strangely, just restart it. OpenCL gives you very low level memory access, it's not hard to corrupt things.

So how did this solution fare? Disappointingly :-(

I define my two input vectors, xt and yt, and one output vector nt. Sadly, while the first few iterations are promising, it appears that we quickly run out of precision here too. With one thousandth as input, the function should return in roughly 31,420 iterations. Clearly it does not.

I tried switching from floats to double, even though my chip apparently doesn't support them, this was no help.

Where to go from here? Mathematica's ParallelEvaluation[] function, which splits jobs across multiple Mathematica kernel, won't really help. Another option could be to switch to integer arithmetic for Mandelbrot's function though I'm not convinced this would improve Mathematica's speed. There's always a chance that I may have done something wrong in my OpenCL code, or that further optimizations are possible in the Mathematica code. A final option that I couldn't get to work was running the OpenCL code on my CPU instead of my GPU. This is theoretically possible and would leverage the CPU's ability to handle higher precision doubles.

Implementation in a different language may be the ultimate solution. C, C++, or Java make most sense to me given they have excellent optimizing compilers but, just for kicks, I picked one of my favorite programming languages: ruby.

Here are the results running on ruby 1.9.2 (ruby 1.8.7 is about 1/2 as fast):

1,          3,        2.0e-05
1/10,       33,       4.4e-05
1/100,      315,      0.000312
1/1000,     3143,     0.003746
1/10000,    31417,    0.031083
1/100000,   314160,   0.300709
1/1000000,  3141593,  3.02154
1/10000000, 31415927, 30.608127

To my surprise modern ruby is significantly slower than compiled Mathematica at this task. I would have expected ruby to fare better.

Interestingly, both ruby and Mathematica bog down significantly when computing 10^-8. They don't return in a meaningful timeframe, i.e. I killed both calculations after 30 minutes. Presumably this is the point where both switch to arbitrary length floating point routines in software.

You have 100 feet of fencing, what shape will give you the biggest field?

That's the question I asked my sons today. It's an interesting problem but to make it a little more interesting and apropos given we're in Australia, I asked them: "If you were a crocodile farmer and only had a 100 foot long fence, what shape would you arrange it in to have the most space for your reptiles?"

I got many different answers: Square! Pentagon! Circle! Oval! Most people assumed square was the right answer but didn't all want to pick the same shape.

So we decided to start with a more general square: a rectangle. Thanks to a length of rope (representing our 100 foot fence) we were able to prototype various areas. A square seemed best. Was that so?

We turned to Mathematica (I just bought the newly released version 8, love it) for confirmation:

The maximum area is achieved when a side is equal to 25 feet. In other words: a square gives us the max area of 625 ft^2.

What about other shapes? Mathematica to the rescue!

A triangle makes poor use of fencing, the square is an improvement but clearly the more sides our fence has, the greater the area... The optimal shape must be a circle!

Though they saw that the circular field's area was greater than the square field's, this still didn't hit home until I plotted both.

Circles rock!