…is to prevent people from putting up Christmas decorations more than a month ahead of time.
Archive for November, 2009
The purpose of the Thanksgiving holiday
Monday, November 30th, 2009Fake pets
Monday, November 30th, 2009My friend just bought himself one of these. It looks like a sleeping puppy; its tummy moves up and down like a real puppy’s and it makes a sound like a real puppy would. Except it’s just a brick, a paperweight.
I have no idea why people would get themselves a fake pet. True, if you don’t inspect the animal too closely it looks real, except it’s not. Would I get it to trick myself into thinking I own a puppy? Or would I want to trick others? Or play a horrible joke on someone where I pretend to kill the little creature. Or is owning a fake pet the first step in the ladder of responsibility (followed by a real pet and then a child)?
P.S. Somehow I managed to keep up the blog for over 200 posts now–a big reason to celebrate!
Color Pickers
Sunday, November 29th, 2009If you’ve looked at the crowdsourced art experiment you may have noticed a little color picker on the page. It looks like this:

My Color Picker
If you’ve seen other color pickers (for example in Photoshop, the Office / iWork packet, or even MS Paint) you’ll notice that this one is slightly different. I made it to have property that a lot of other pickers lack: it displays all possible colors on one two-dimensional plane. If you think about it, the other pickers you’ve seen either have an additional slider that changes the 2D plane (e.g. Photoshop or the built-in Windows or OS X one) or they don’t allow you to specify some colors (e.g. the Pantone picker or a lot of the pickers online).
As you know, I’m fascinated with color, especially when there’s math or technology involved. My picker happens to involve both and so here we go.
The color space is three-dimensional, that is, to uniquely identify a color, you have to specify three dimensions. There are many ways to specify a color: the most common one (albeit not the more natural one to understand) is the RGB space: each color is identified by the intensity of pure red, pure green and pure blue components that, when mixed together additively, construct the desired color. I emphasize additively because when we think about “mixing” color (when we paint with oil or watercolor) we don’t actually compose color the same way our eye does. In the RGB space, there are three numbers you specify for each color: and so yellow can be defined as (1.0, 1.0, 0.0) because it consists of max intensity red and green and no blue. Violet (like the color of this flower) can be defined as (0.6, 0.3, 0.7).
Similarly, there are other ways to describe a color: the HSL space, that I find fairly intuitive, describes a color by specifying its hue (the location on the rainbow), its saturation (how vibrant is the color) and lightness (how bright it is). Again, three dimensions (why the color space is three-dimensional is an interesting question…).
This fact makes it hard to design user interface elements that allow you to pick a color (color pickers): the screen is two-dimensional so you either need a slider or some other way to change the third dimension, or you will see a selection of all colors. Being a visual person, I wanted to have a picker that displays all the colors at once, without some stupid slider.
My first attempt took advantage of the fact that on a computer, every measure is discrete (there is no such thing as infinity in computing) so I can collapse the three dimensions into two simply by cleverly rearranging where each colors should be placed. Assuming that each color component has 256 degrees of intensity (which is the case in computer screens these days), we can list all colors, for example
(0, 0, 0), (0, 0, 1), …, (0, 0, 255), (0, 1, 0), (0, 1, 1), …, (255, 255, 255)
We can now map the sequence into a two-dimensional one, for example
(0, 0), (0, 1), …, (0, 4095), (1, 0), (1, 1), …, (4095, 4095)
The problem, however, is that we want the mapping to be smooth, i.e. ideally we would like nearby pixels to have similar colors, and the mapping above (and in fact most mappings) won’t guarantee this.
This is where math comes in handy, specifically the field of space-filling curves. I kept one dimension (say, the blue component)–that will be my X coordinate of the resulting picker. For the other, I used a Hilbert-like curve to collapse the green and red components into one Y coordinate. A nice thing about Hilbert curves is that they are somewhat smooth: in this picture, if you pick two neighboring points they are likely to be close to one another on the curve. I’ll leave as an exercise for the reader to determine the actual expected Euclidean distance in color intensity for randomly picked two neighboring points on a Hilbert curve.
Well, such was the first experiment. The resulting “color belt” was very long (because collapsing two dimensions into one makes it a very long dimension!) and the lack of smoothness was pretty obvious (click to view the full image):
I then took the belt and made it into a ring, by “curving” the long dimension around (to take advantage of the fact that the circumference gives me 2π more space than the radius:
Besides looking very Tolkenian, the ring has a pleasing æsthetic to it. Still, it’s somewhat hard to pick out the color you want because the colors are fairly scattered (if your mouse if off by one pixel you may be picking a totally different color).
The next approach was to be a little smarter with the choice of dimensions. Instead of picking one of the components to be one dimension and try to collapse the other two, I chose the light intensity of a color as the horizontal dimension and then collapsed all colors of a given intensity into the vertical dimension. The advantage of this approach was an increased smoothness: all colors along a vertical line had the same intensity; and because the intensity function is linear in the values of R, G and B (it’s a weighted average of the red, green and blue intensity), the colors on a horizontal line are all similar.
I also varied the order in which colors would be placed on a vertical line, based on a heuristic of the R, G and B component. Some of the choices gave very interesting results. For example, if I plotted each vertical line based on the lexicographical order (sort by R, then G, then B), I got a picker that looked like this:
I got really interesting results when I made the heuristic slightly more complex: for example, if I ordered the pixels by the value of the sum of squares of the colors, I got
Finally, in order to bundle similar colors together (i.e. have fewer “boundaries” where neighboring colors differ significantly at the expense of more pronounced boundaries), I used a heuristic that “favored” one component over another. The image on the right, for example, orders pixels like this:
- In first order, pixels whose blue component is higher than their red component, appear higher in the image
- Then pixels whose green component is higher than their blue component
- Finally pixels whose red component is higher than their green component
The little picker at the very top of this post is a slightly massaged (reduced and despeckled, to make picking more accurate) version of this approach with a lexicographical order of pixels. I also added a pure gray gradient on the side–even though the picker itself contains every shade of gray, they are scattered throughout the image. If you’re interested, here is what the picker looks like if I order the pixels by saturation, it looks… phantasmagorical:
Source code for all color picker generators:
- Color belt and color ring generator: ring.php (it generates a PNG file, so redirect the stdout to a file, say output.png)
- A useful cheatsheet of color conversions (source unknown): colorConversions.txt
- Layered color picker: picker.c (if generate a PBM file that Photoshop/ImageMagick can read, so redirect the stdout to a file, say output.pnm)
What is Creativity
Saturday, November 28th, 2009Creativity is the ability to imagine–the ability to “see” (but not necessarily with your eyes, or even visually) something before it exists.
A big problem with defining and assessing creativity is that “existence” is not a well-defined word. Existence can be interpreted very narrowly or broadly, and depending on how you interpret it, something is either creative or just an imitation.
The ability to mimic others (i.e. the ability to learn) is one of the reasons why we have been so successful as a species. We are all great imitators–so great, perhaps, that there is no creativity at all?
Or perhaps creativity is the ability to construct dreams. Our brains construct dreams all the time–they are the authentic creators. But not all of us have the ability to do this consciously.
Or maybe we’re all creative because we all interpret things slightly differently. Most of us simply choose not to speak up.
Humor and story arcs
Saturday, November 28th, 2009There’s been books, university courses and I’m such also TV shows about humor: what makes us laugh and why. I think the answer is very complicated and depends on personal characteristics as well as the individual’s experience and mood.
There is one thing that I respect in humor, especially humor in storytelling, which I think is a fairly universal quality, and that is the “arc” structure of stories: the idea that humor builds on itself by–almost in a fractal manner–having a larger story composed of many thematically-similar smaller stories.
This structure is usually evident when you listen to stand-up comedians. Their stories feature plenty of puns and one-liners. But they are stories–they are composed of threads. Each thread builds up to a funny conclusion, and each thread contains many puns and one-liners. We can go further–several such stories create a set up for a really funny pun at the very end that connects (in an arc-like fashion) many threads. There can be more levels, but, understandably, it gets more and more difficult.
It you look around, some of the best humor is organized in this very way. Seinfeld (or, more purely, Curb your Enthusiasm), for example, follows this recipe: the final pun is usually built up over the duration of the episode, with individual threads which by themselves are funny. Chris Rock’s Kill the Messenger is by far my favorite show that has this property as well. While most humor has two such arc “levels”, good stories use three, or more, levels. The real challenge is to operate within the arc structure while not seeming artificial. The most talented comedians will make the connection between the arcs so seamlessly that the theme only becomes apparent as the comedian is about to offer his or her pun.
No such thing as a free lunch
Saturday, November 28th, 2009The other day, a friend of mine wanted to use technology to automate some reports he needed to generate. I described to him the options he has: he can either put the time to find (and to learn to use) the right tool that empowers the non-technical person to create reports, spend money on a consultant who can whip the reports, or duct-tape something himself but understand the consequences of such a myopic solution (e.g. it gets very difficult to maintain the reports after they reach certain complexity, easy things are very easy but hard things are impossible, etc.). He asked me something that at first stunned me; he asked “why can’t this be done fast/cheaply and well?”
One of the most difficult things for non-technical people to understand is that technology solutions are expensive. Worse–many technology solutions that seem like they should be cheap are expensive. Essentially my friend came up against a classic problem of technology and software development: what is easy to describe/visualize is often very difficult to code up. For that reason, making technology that empowers business users is expensive because small changes in business requirements may lead to large changes to the software. We are therefore left with two poor options: to spend a lot of time/money up front building something that is flexible and operates on concepts familiar to the user (as opposed to some technical conventions), or to continue spending even more money building one-off solutions.
There are two dimensions that people usually care about: time and cost. Everything else (quality, flexibility, user experience) can be expressed in terms of these two dimensions. You can trade one off against the other but you can never lower both. In other words, there is no such thing as a free lunch.
At this point, I reflected on one point that I used to consider as counterarguments to the above: what about quality? Surely there must be some advantage to hiring a smarter software engineer, or one that understands the business user better.
True, there is an advantage, but it comes at a cost. Quality is nothing else but an investment in a solution that makes future changes (or troubleshooting) easier. It can manifest itself as code that is written more cleanly, adhering to accepted best practices (so that a future developer can understand the code easier and thus make changes faster), or more flexible (so that less code needs to be rewritten if the requirements change), or more user-friendly (it takes the users less time to use the tool). High quality code will cost you less in the long run, but it will cost you more today: you will have to hire an experienced developer, or a smarter one (one who has the gift of foresight), or have them spend more time (=$$!) understanding the business so that the user experience is improved.
Many startups bias themselves toward time-to-market: getting something out today that works today. As those companies grow larger, technology becomes more convoluted (and thus harder to improve) because a lot depends on this poor quality code that the early technologists wrote to solve the problems of the day. Ultimately innovation is stifled because even the smallest changes become risky and nobody wants large system overhauls without a clear ROI, especially that what is already in place works.
This dead end is caused by two compounded factors: the business people have a myopic understanding of value and cost, and the technology people have a hard time assessing either. So if you have a startup, ensure that your technology people can tell your business people how much something will cost, not today, but in its lifetime (this includes an assessment of a lifetime of a particular solution–nothing lasts forever!) and ensure that your business people can make decisions based on the long-term as well as the short-term view.
The right answer is somewhere in between. It would be dumb to spend a lot of money building extremely flexible solutions because fast time-to-market is crucial in a startup. But invest some money up front (by either hiring smart engineers and experienced engineers–you need both–or introducing governance) and build in guardrails that make it cheaper to make changes in the future.
The consulting industry and entropy
Thursday, November 26th, 2009I like entropy because it’s such a simple concept that’s easy to define (a measure of disorder) and universal (it looks the same throughout the universe). Its definition doesn’t depend on other words that can be loaded (such as “happiness” or “language” or “intelligence” or even “evolution”) so it’s a good term to use as the basis of a framework for thinking about life.
Entropy in the thermodynamic sense has a close equivalent in the field of information theory. In fact, its equivalent is so close that it’s also called entropy. It is a testament to the universality of the concept — in fact, I truly believe that I could define everything I can think of in terms of entropy. Perhaps one day I’ll publish a dictionary that does precisely that.
In the meantime, my friend, wishing to see me suffer, challenged me to define a seemingly unrelated thing in terms of entropy. Here it goes.
I’m intrigued by the consulting industry, specifically management consulting. At first I had a somewhat cynical view of it (in fact, as I saw many of my friends prepare for interviews that seemed to ask nothing but Fermi problems. Ironically, most of my friends didn’t know they were Fermi problems… here’s a cheat sheet if you’re preparing for a consulting interview). I interacted with consultants at work (and saw the best of them in the movie Office Space) and found it very difficult to understand how they can be adding any value. After all, they don’t bring any skills to the table. Most importantly, there was an unsettling stench of slickness to many of the consultants I’ve interacted with, almost as if every conversation was a game to be won or lost (or–again, taking a cynical view–as if it was through the slick conversations that the consultants were making an impression of adding value).
Then I thought about it some more, in the abstract, starting from what I imagined to be the history of consulting. I had this impression of the consulting industry as being pioneered by a few incredibly smart people (university professors perhaps)–I call them “founders”–who worked out through the theory of efficient management, information flow and social interations and determined some theoretical framework that they published in a seminal work in the mid-1950s. Following them were ambitious and innovative entrepreneurs who decided to put their theory in practice–they worked out the kinks that usually prevent the elegant theory from being applied to the real world (this is also probably the reason why we hear about groundbreaking research in battery technology yet nothing seems to reach the mass market). I call these people “visionaries”. They came up with principles and set up the first consulting companies. Over time, as it always happens, the principles were lost and the companies lost sight of their mission and their roots; it all became a matter of making money (incidentally, this happens to a lot of industries which is why sophisticated enough companies all look the same, regardless of what they do). Surely, then, in theory consultants add value, even though what we see today obscures it well. Let’s find it (and let’s use entropy to explain it!)
Entropy in the information theoretical sense measures how much information some data contains. A string of zeros: 0000000000 contains no information while a random string of zeros and ones: 001101001011101 contains plenty of information. In other words, entropy tells you how predictable the data is. We can also talk about entropy rate–a measure of the “density” of information. For example, English text has an entropy rate of about 1 bit per letter, which means that if you were to represent English in the most efficient way (but without losing any information), Shakespeare’s Romeo and Juliet would take up about 169 thousand bits. Note that the most popular representation of English today on a computer is to use ASCII (assign an 8-bit sequence to each letter) at which point the same play would take up about 1.3 million bits in such an encoding–the amount of information varies depending on the encoding and this is why entropy assumes you find the most efficient such encoding.
Of course entropy rate depends very much on the domain of the information. While entropy rate of English is 1 bit per character, entropy rate of, say, the scripts of soap operas is much lower than that. It’s because what is said in soap operas is much more predictable–fewer sophisticated words are used.
While it’s hard to find the theoretically correct value for the entropy rates of data, a good first-order approximation is to compress it using a good lossless compression algorithm (for example, make a zip of the data) and look at the compression ratio. For example, Romeo and Juliet takes up 165kB (which translates to the aforementioned 1.3 million bits). Once you compress it, the text takes up 63kB. The compression ratio of 38% means that the entropy rate of Romeo and Juliet is about (38%*8 bits per character that ASCII uses) = 3 bits per character. More than regular English, but, there again, Shakespeare is a little less predictable than your average Joe (plus, there’s overhead of the compression program itself, and it’s not ideal, too).
Now the punch line: consultants are often brought in to synthesize information and come up with recommendations. While the recommendations are usually commonsense, the synthesis is hard. They have to interview lots of people, look through reams of documents, stare at various charts and graphs. This is a lot of information. At the end of their engagement they come up with a powerpoint document that summarizes the important findings. It’s usually an incredibly dense powerpoint — carefully chosen words, terse bullet lists, not even full sentences, articles and prepositions are the first ones to go. If they’ve done the synthesis right, they were able to fairly losslessly (given what they were supposed to recommend on) compress the information into a powerpoint. Hence, the way to assess the value of their work, simply find the entropy rate of their deliverables. High entropy means high value.
You don’t even have to bother reading the powerpoint document!
The greatest moment in my lifetime of interactions with computers
Tuesday, November 24th, 2009For those who prefer brevity to beauty, here it is: the day I discovered DOS/4GW. For everyone else, read on.
Thanks to my dad’s wonderful prescience, I grew up with computers–and by grew up, I mean grew up. I think the first computer in the house was a Commodore (although for some reason I imputed a memory of my dad owning an Amstrad-Schneider). I was too young to remember much other than sitting on my dad’s lap and staring at the computer screen. Back in the day it was impossible (and I believe also illegal) to own “imperialist” equipment (I know one needed the governor’s permission to get a car) and so I am deeply impressed by my dad’s ability to do magic.
When I was six or seven (again, I don’t remember exactly), I got my very own ZX Spectrum + with a black-and-white monitor. I remember playing with it for hours (the fact that those years spent staring at a CRT screen haven’t made me blind confirms my theory that if you grow up with something you get used to it and it doesn’t harm you; ironically many of my friends who got their game consoles or computers when they were teenagers are nearly legally blind now).
Pretty quickly I started writing programs for it. Looking back, this was crazy–the user manual was in English and so at age seven I knew about eighty words–keywords used in programs I’d write–in English very well but no grammar or vocabulary that kids my age for whom English was their native language knew (a fascinating way to learn the language).
I don’t want to digress too much from the theme of this post; one day I’ll continue the rant. The important thing was that at the time the computer had 48k of memory available (an equivalent to the amount of information contained in the text of the Constitution of the United States of America; to put things in perspective, computers come with 2GB now, which is about 40 thousand times more). I didn’t feel I needed much, though, because the capabilities of the computer were limited and my brain was pretty small, too. Over time, however, I did start bumping into these limits more and more. I could define my own characters and sprites (for which I had to learn to operate in binary; knowing binary before I knew how to divide is a funny thing, now that I think about it) but I could define at most 256 of them.
Fast forward six years, to my first PC (getting close to that ominous greatest moment). Eternally curious how to make games rather than play them I’d continue programming. My brain, now more fully developed, could process more information and so I expected my programs to. The PC was also capable of much more (I think I had 16MB of memory at this point?) yet due to the hardware limitations I could use at most 640kB of it. You may think that a little more than 650 thousand bytes should suffice but that’s how much information is contained in a single uncompressed photo! I felt very constrained–my computer could play sound, display graphics, and perform calculations much faster than anything I’ve seen before. Yet I couldn’t take advantage of any of it. There seemed to be some kind of a rule that stipulated those omnipresent limits–party poopers. There seemed no way around it.
Then, one day, I discovered this utility called DOS/4GW. It wasn’t a discovery as much as a result of an investigation: I’d see more and more advanced games pop up that surely couldn’t have been subject to the 640k limit (they combined music with graphics and seemed to store a lot of information about the virtual worlds they were depicting… my intuition told me that must have been more than the measly 640k). All these games would launch a small application before they themselves started, and that application would simply pop “DOS/4GW” on the screen and disappear. So I started digging.
I found out (at that point I didn’t have any access to the Internet–searching for information was so incredibly painful back then) that this little utility allowed the game programmers to bypass the 640k limit, effectively taking advantage of all the memory that the computer had available. And to my shock it turned out that I could also take advantage of this application when making my programs.
This lifting of the limit was, in retrospect, the single most eventful day in my entire life of interaction with computers. For one, the limit was immediately increased from 640k to 16M (a 25-fold increase!). But, more importantly, it was a soft limit: I could simply buy more memory and have more available to my programs. I felt empowered*. I went crazy–there were finally no limits to my creativity.
* What I didn’t know was that DOS/4GW didn’t abolish the limit altogether; it simply upped it to 4GB. But given that most of us don’t have that much memory even today, that fact wouldn’t have registered with me as something fundamental then. Now it’s part of the sad reality about modern computing–it’s all painfully finite.
That funny feeling (part III)
Tuesday, November 24th, 2009I’m skipping part II for now; it concerns a feeling of confusion yet bliss that I’ve had several times in my life that fascinated me but that I found almost impossible to describe. One day I hope to be able to write about it.
There is another feeling that I’ve had that I found much easier to write about, because it’s very tactile and concrete. I’ve had it maybe a few dozen times in my life; each time it lasted maybe for a minute. I guess it can be compared to a high but it feels very natural and right (and I can’t correlate having it with any substance I could have taken; it happens out of the blue, during the day. I don’t recall having eaten or drunk anything unusual before any of the times it happened).
I feel a sudden rush. My sense become more acute. I can feel my eyes moving much more rapidly. My mind is suddenly much clearer, sharper. Time seems to almost stop, or it’s me that thinks and moves really fast, I can’t tell exactly. It’s as if the electrical signals in my brain intensified manifold.
When it happens I’m usually in the middle of thinking about something and often also typing or writing. The feeling usually lasts a minute; a minute that seems to take forever; but a minute that seems the most productive minute of my life. Information that originates in my mind seems to get reduced to quanta at an incredible rate and transformed into words that appear on screen, almost as if the notepad or the computer screen had some ethereal connection with my brain.
I’m fascinated by these things precisely because they happen naturally. They are a testament to the complexity of our brains. The fact that they are so hard to describe highlights the limitations of the human language (or, conversely, the expressiveness of the human perception).
Great physicians
Monday, November 23rd, 2009Great physicians listen to the patient.
I remember this pediatrist my mom would take me and my brother to when we were young. I thought she was the devil (note that I was little and haven’t quite internalized the character of the devil; I think I equated it with a supernatural and conniving being). For example, there was this one moment I remember incredibly vividly: she would ask me to blow my nose into a handkerchief (presumably to see whether my nose was blocked or something). As I was about to blow she would point out that I should blow each nostril separately, otherwise my nose would bleed. Nonsense, I thought to myself (it was too late to actually follow her advice, so I didn’t actually do anything to spite her even though if I had the time I would so I guess I was spiteful), I’ve been blowing my nose both nostrils together for nine years of my life and have never, ever seen blood. Lo and behold, the handkerchief was slightly bloody.
She was not a great physician. She never listened to me. She never cared what I had to say, how I felt. She would always listen to my mom: she would ask her what was wrong with us, listen to her responses and prescribe medicine based on that. We were just black-box biological systems for her.
I think this lack of a connection with the patient made her overestimate our symptoms and, consequently, overdiagnose and overtreat us. I was a sickly child.










elevenseconds.com
blog.elevenseconds is powered by