Monday, February 25, 2013

Anonymous Functions

There's a certain joy that comes of figuring out something yourself that you don't really get when someone else teaches you (although the best teachers teach in such a way that you're constantly figuring things out yourself).

I've never taken a computer science class in programming, so most of what I've learned I've figured out for myself. There are many little milestones along the way, but there are some big ones that stand out as large leaps forward in understanding. The day I suddenly understood classes in Python, for instance. I'd read the documentation on them several times before, but had never been able to make heads or tails of it, until the day when I really needed to use which point it all suddenly clicked, and I reread the documentation and understood everything. It was an exhilarating, empowering feeling. My abilities as a programmer grew a bit that day, and I've used classes often since to write better code than I otherwise could have.

Last Friday I had a similar experience, suddenly understanding lambda functions in Python (known more generally as anonymous functions). (I also understood two specific functions last week, but that's not quite as interesting or exciting as understanding a whole new class of object.)

Lambda (or anonymous) functions are functions that you create when you don't need or want to go to the bother of defining a full-fledged function. Sometimes all you need is a simple function for one particular part of your code that you don't intend to use anywhere else, for instance if you need to square each item in a list of numbers. It's such a trivial thing that it isn't worth the trouble of writing a separate function for, especially if that's the only place you're going to need it.

Instead, you can write a simple lambda function to do the work for you. For example, given a list of numbers:

someList = [1, 2, 3, 4]
for number in map(lambda x: x * x, someList):
This code would then print out 1, 4, 9, 16. (Incidentally, the map function is one of the other functions I understood last week, as it works closely in conjunction with lambda functions.)

Basically, the map function takes all the items in an list (such as someList) and applies another function to them. The "lambda" there signifies that I'm defining a function, and the "x" means that it's only got one variable; the part after the colon, "x * x" means to take the input of the function and multiply it by itself (squaring it). So, "take each item in someList, and multiply it by itself". The print(number) part simply tells the computer to display the results of the operation on screen; it has nothing to do with printing on paper.

Anyway, it's really wonderful to be exercising the creative aspects of my brain in my job, and learning new things as I go along. A hui hou!

Wednesday, February 20, 2013

Multilingual Machine

Partly as a result of my new job, I've begun stopping at the local Subway restaurant more often for lunch. Having also developed an appreciation for toasted sandwiches I've had ample time to notice things about the place while waiting for my sandwich to toast, including the fact that the toaster oven is apparently multi-lingual.
The LCD panel that displays things like the time helpfully informs people that the door is open whenever it is, but it does so in different languages each day. I've seen it in English, Spanish ("la puerta está abierta"), Portuguese ("a porta está aberta"), French ("la porte est ouverte") and even German ("Tür ist offen").
I'm not sure if the machine rotates of its own accord in an oddly touching attempt to facilitate communication with as linguistically diverse a group of sandwich-toasters as possible or if it's trying to teach them new languages one sentence at a time, but it's fun to notice. I wonder if the ovens in other Subways do it as well? Anyone care to confirm or deny?

Monday, February 18, 2013

Mystery Meteor (and poor upstaged 2012 DA14)

Given the amount of news coverage it's received, I doubt many of my readers are unaware of the meteor that exploded in Earth's atmosphere over Russia last Friday.

However, in case some of you are: at about 9:20 in the morning (local time, and I'm not even going to bother trying to convert) on February 15, a meteor entered the atmosphere and exploded over the city of Chelyabinsk, Russia. It and its effects were recorded on dozens of different cameras, and boy howdy did it have an effect. It briefly outshone the rising morning sun in brightness (!) before exploding in the atmosphere with a force comparable to a good-sized nuke, shattering windows in at least six cities around the region, collapsing the roof of a nearby zinc plant, and putting over a thousand people in the hospital (mostly with injuries from the flying glass caused by the explosion). (Contrary to what is commonly assumed, things entering the atmosphere don't heat up because of friction, which is negligible at that speed, but because they're traveling so fast the air in front of them doesn't have time to get out of the way and is instead compressed. And compressing air makes it hotter, which causes it to glow at visible wavelengths.)

By remarkable coincidence, this meteor struck the Earth only about 15 hours before the (expected) closest approach of the asteroid 2012 DA14, which whizzed harmlessly past as predicted and pretty much got lost in the commotion. Astronomers world-wide will now have to spend countless hours trying to refute the conspiracy theories that we knew about this beforehand, or that the predictions about 2012 DA14 were wrong and the objects were related (which they weren't, coming from almost completely opposite directions). C’est la vie for an astronomer, though.

Anyway, there are no hard numbers on the impacting object, but there are some educated guesses. Estimates of its size range up to 7,000 tons, making it the largest object to strike the Earth since the 1908 Tunguska event that flattened trees over 1,250 square kilometers (830 square miles) in a remote part of Siberia. The Tunguska event due to its remote location had very few witnesses so details are sparse, but it is estimated to have released energy on the order of 10-15 megatonnes of TNT (about 43-62 petajoules). This was actually about 20 to 30 times more than the energy from the meteor that hit on Friday, which is estimated at about 300-500 kilotonnes of TNT, (2,100 terajoules, about 2.1 petajoules). However, that amount is still about 20 to 30 times larger than the amount of energy given off by the fission bombs dropped on Hiroshima and Nagasaki. The explosion it caused was large enough to register on systems that listen for clandestine nuclear tests.

(Note that I'm calling these event "impacts" and saying they "struck the Earth", despite the fact that neither object actually hit the ground. From the point of view of an astronomer, the atmosphere is a practically infinitesimally thin covering compared to the size of the Earth itself, so something hitting it is basically equivalent to hitting the Earth.)

It's a good thing this object – estimated to be perhaps 15 meters (50 feet) across, smaller than 2012 DA14's 50 meters (160 feet) – hit the atmosphere at the low angle it did (about 20 degrees) rather than more head-on, considering it was probably traveling at 15 kilometers per second, over 10 times faster than a bullet from a high-muzzle-velocity rifle. Videos of the event show what appear to be two separate contrails, implying the object split up prior to entering the atmosphere (it may even have been a binary asteroid). Exploding as it did with the power of a mid-sized nuclear bomb, it's a miracle nobody was killed, though Russian sources still report almost 1,200 people checked into hospitals as a direct result.

This number of injuries and the amount of property damage it did, though, instantly catapults this object to the top of "most destructive meteor in recent history". Prior to this, there have been reports of one or two people hit by (small) meteors with no lasting results, and unsubstantiated reports of a dog in Egypt killed by a meteor in the early 1900s. It's going to be very, very, interesting to see what, if anything, this event does to change public perceptions of asteroids. Objects this size are predicted to hit the Earth about once a century, and astronomers have long been aware of much larger objects – such as 2012 DA14 – that also have the potential to hit the Earth.

Up until February 15th, though, it's always been a pretty theoretical argument. Astronomers have had a hard time convincing people to give them money to build monitoring systems that could warn us of such things in advance because there wasn't much in the way of perceived need, although thankfully the U.S. government has put some money into building such systems, such as the PanSTARRS telescope located on Haleakalā, Maui. However, this object, which could have obliterated the city of Chelyabinsk rather than merely damaged it had it come in at a different angle, would have been very difficult to detect before it hit with the current asteroid-detection systems we have (as evidenced by the fact that we didn't detect it prior to impact). Astronomers estimate there are still tens of thousands of objects capable of destroying cities out there that we haven't found yet, and it's only a matter of time until one hits us again.

Of course, simply knowing something is going to hit you and destroy X city or cause widespread tsunamis around the shores of Y ocean isn't very useful unless you can do something about it. I'll be honest: we don't actually know if we could stop an asteroid from hitting the Earth. But that's mostly because we've never tried, because we've never seen a strong enough need to do so, because asteroids have always been "something up there that doesn't bother us". I'm sorry for the pain of everyone who was hurt by this asteroid, but I hope that it will help wake up the general public to the fact that asteroids are not just a theoretical danger – that living on the exterior of a giant ball of rock hurtling around the sun at 30 kilometers per second, surrounded by thousands of similarly-speedy rocks is not necessarily safe. And maybe, just maybe, the next time one of these objects is going to hit us we can spot it while it's still far enough out for us to do something about it.

Tuesday, February 12, 2013

A Long Day of...Not Work.

I got in to work this morning only to be informed that the internal office network was down, barring everyone from logging on to their computers and bringing productive work to a screeching halt (except for the people with laptops and stuff able to be done on them). We weren't sure how long it would take to fix, so everyone waited around (more or less) the whole morning, before our boss told everyone not to bother hurrying back from lunch since it didn't look like it was going to be fixed very soon. After a nice relaxing two-hour lunch break I spent another hour twiddling my thumbs and reading up on a book about the Perl scripting language one of my coworker had lent me, before our boss finally called it a day at afternoon tea and sent everyone home early.

So that was an interesting experience. Hopefully things will be back to working tomorrow, and I can find out if my projects I left running over the weekend finished successfully.

(Edit: Thankfully, my computer was back up and running by Tuesday, and everything else was up by Wednesday, so I managed to still be fairly productive this week.)

Monday, February 11, 2013

Weather in Hilo

One of the nice things about living in Hilo is getting to see weather displays like the one below from time to time.

This comes from the Sun going down above the roof of the building next to where I work. It had been raining off and on all day, and on my way to work in the morning I was actually trying to get pictures of the puddle-reflection of a vibrant rainbow that was in the sky. None of them really came out well enough to post, sadly. Maybe next time. It sure made a pretty reflection in the puddle, shivering each time a drop of water well from the power line above or a passing car stirred the surface in its wake.

Monday, February 4, 2013

Experimental Fudge

So having (re)discovered last year how easy it is to make fudge, and being the fudge-lover I am, it is perhaps not too surprising that I would begin experimenting with different kinds of fudge, as I tend to do with every new recipe I learn to make.

This time, specifically, I was waffling between different brands and bag sizes of chocolate chips at the grocery store, when I noticed a bag of white chocolate chips. I love white chocolate, so on a whim I bought some and used them to make fudge over the weekend.

It actually turned out quite good, something I wasn't sure of given the different compositions of white and regular chocolate. It may have helped that I deviated slightly from the recipe and kept heating it after I was supposed to stop to make sure all the marshmallows and white chocolate chips melted, which made it nice and molten when I poured it into the pan.

So, the conclusion appears to be that white chocolate chips are a perfectly suitable substitute for brown ones in fudge, although the resulting product may be ever-so-slightly crumblier than normal. It still tastes delicious, though. Try it sometime!