Wednesday, November 12, 2008

Wikipedia wants you to be mauled by a bear

Holy cow, a post!  It's not at all what I usually write about, but it's better than nothing.


Thursday, June 19, 2008

Experiments on habits

As you might have read in a previous post, my company is able to innovate so quickly because we keep don't hesitate trying out new stuff. If someone has an idea, it can go from a vague thought to running on live traffic in a matter of weeks. If the numbers say that it's a good idea, we keep it. If not, we throw it out, no regret. My coworker has an interesting post about how we do some form of A/B testing.

Experimentation is at the very heart of science. If you don't try anything new, you can't learn anything. This is why I try to vary my habits from time to time to try something different. Last November I spent the whole month without drinking caffeine. I wanted to prove that "I can stop whenever I want to but I just don't want to" was true for me. Also, I wanted to know if I would be more or less tired, sleep better, etc. Overall, I found that after a few days of not consuming caffeine (coffee, tea, coke, etc.) I didn't really crave it at all and that it didn't affect my overall health level.

Since last Monday I've started to eat vegetarian. I've been talking about this for months and finally did it. Well, I've actually been told that since I decided to eat seafood I'm rather a pescetarian. I'm not a very difficult person when it comes to food, I'll eat anything. So it's been weird for me to start being picky about what I eat, I feel almost guilty.

Thus far, I've been kind of hungry a lot. I'm eating a lot Indian food because they have a lot of very tasty meals without meat. That, salad and pasta.

I haven't decided exactly how long I'm going to keep this up, at least until the end of June, maybe a few weeks longer, I'll see how it goes. I have no intention of this becoming a permanent thing.

P.S. I actually meant to start this last Friday. I did, but then I accidentally eat a chicken caesar salad for dinner... Not a very good start!

Sunday, June 8, 2008

How much do you value your life?

Let's say you're asked how much a human life is worth. To avoid weird looks in most circles you would answer that it's invaluable, we can't quantify something like that. Of course, I don't hang out with what could be considered normal people so my follow up question would probably be "which life?" ;)

Let's use our own life as an example, as it's the one we're all most familiar with. We put a price on our life with our every day actions without realizing it. When you decide to drive instead of taking the bus, you gamble your life away. It's much more likely you'll die while driving than while taking the bus. But you think that the time and comfort savings are worth the chances of you dying in a car crash, and so you take the car. How about when you decide to buy more expensive fruits and vegetables. The taste might be similar to cheaper ones but the more expensive organic fruits are generally better for your health, and thus more likely to increase your life span.

Stanford professor Ronald Howard invented a concept called the micromort. A micromort is a one in a million chance of death. In other words, it's the amount of money you would have to give to someone for them to risk a one in a million chance of death. If someone's willing to receive (or, more likely, save) 20$ for a one in a million chance of death, then we can infer they value their life at 20 million dollars.

There's this book I like called Making Great Decions in Business and Life where the authors use this concept to analyze a car purchasing decision. They, previously in the book, penned the human life at an average of 10 millions, so 10$ for a micromort. I'll quote from the book:

Consider buying a car. For each million lighter cars--those weighing less than 2,500 pounds--that are on the roads, 109 people die each year. For each million heavier cars--those weighing 3,500 pounds--that are on the road, only 53 people die each year. If we use an average of 10,000 miles per year per vehicle, then each mile driven in a smaller car costs the driver 0.0109 micromorts while each mile in a larger car costs 0.0053 micromorts. If you keep this car for 100,000 miles, then the smaller car has a safety cost of $10,900 (1,090 micromorts times $10 per micromorts) while the larger car has a safety cost of only $5,300 (530 micromorts times $10 per micromort). The larger car undoubtedly costs more to purchase and operate, but given everything else equal--don't consider the smoother ride, the bigger trunk, or the worse mileage--it is worth $5,600 more purely on safety.

Think about this concept as you make trivial decisions in your daily life and you'll be amazed at the amount of risks you take.

Sunday, June 1, 2008

Wondering what I do for a living?

I know I haven't been writing anything lately and I apologize to whoever might read this blog (hi mom!). I don't usually post work related things but there's an interesting article in the NYT about my group at Google that might be of passing interest to people who know me. Maybe you'll better understand why I think the way I do when you see the kind of people I spent my work weeks with.

That is all. I've got a great post coming up, it's been in my head for months, I just need to put it down on paper... well, computer, whatever.

Tuesday, April 22, 2008

Male restroom etiquette

I'd love to write a whole article about this, but the video covers everything that needs to be said.

Friday, April 11, 2008

So much for automated traffic cops

Looks like a few cities couldn't resist the temptation of easy money from their constituents. Six cities have been found to have shortened the yellow light duration after installing red light camera. This has the effect of catching more people on red lights, at the cost of causing more accidents.

What is wrong with those cities' government? I thought they were supposed to serve the people, not get them read-ended.

Through Techdirt

Friday, March 21, 2008

Monte Carlo simulation

Sometimes, figuring out something deterministically is hard.  Sometimes, it's just plain impossible.

Let's say we have a model and we want to make sure that model is correct.  The best way to do that is to mathematically prove that it is correct.  This works well for simple model, but when you have insanely completed models it become a huge pain to try to prove it right.  What can you do to validate it?  We can use something called a Monte Carlo simulation.  This is also known as statistical sampling.
Here's how wikipedia describe the Monte Carlo method:
  1. Define a domain of possible inputs.
  2. Generate inputs randomly from the domain, and perform a deterministic computation on them.
  3. Aggregate the results of the individual computations into the final result.
I'll use the simplest of example to show how this can be done.  I want to write a test to know if a number is even or odd (told you it was going to be simple).  I'll write some code to test it:

def is_even(number):
  if number % 2 == 0:
    return True
    return False

This is Python code by the way, but it should be simple enough even for non programmer.  It's a function called is_even that takes an integer and returns true if the number modulo 2 is 0 and false otherwise.

Let's run a monte carlo simulator on that function to make sure it's right.  We'll generate n random integer between minus one billion and a billion and we expect that around 50% of them will be even.  We'll set n at a reasonable 100 000 runs.  The higher the number of runs, the more accurate the result will be, or rather the higher the confidence in the results will be.  It should look like this:

import random
n = 100000
number_even = 0
for i in range(n):
  random_number = random.randint(-1000000000, 1000000000)
  if is_even(random_number):
    number_even = number_even + 1

print '%f%% of numbers are even' % (float(number_even) / float(n))

When I run this I get this message back:
0.501340% of numbers are even

And without any kind of mathematical proof we have validated the model.  Though it's important to realize I haven't actually proved anything, I've simply shown that with a high probability (I'm too lazy here but we could actually find the confidence interval relatively easily) the model acts a certain way.

This example was, of course, way too trivial.  But this kind of reasoning is very useful when a system has too many different components which makes it difficult to accurately predict, such as a traffic flow system (think about elevator planning for example).

Red lights cameras

Think red lights cameras will pay for themselves with the fines they bring? Think again. It seems the city of Dallas has been having some issues with it's camera problem.

They figured the cameras would bring in 14.8M$ in revenue last year but they only brought 6.2M$. Why? People figured out that going through a red light with an automated system that fined you wasn't a very good idea, and so they stopped doing it.

What is Dallas doing? They're shutting down some of the cameras because they're not bringing in as much money as expected. This brings up an important issue: are the cameras there to increase public safety or are they there to increase revenue?

They're also thinking about idling some of them. An idle camera is very cheap to maintain and the desired safety effect will still be there (as long as they rotate which camera are idle).

(Found through Freakonomics.)

Monday, March 17, 2008

Airplane boarding

A year ago, I was 22 and I had only taken a plane once. Since then, I've taken six trips using an airplane. As an amateur optimizer, the whole process of boarding the plane always seemed inefficient to me. But much work has been put into finding efficient boarding algorithm, this page seems to describe the different methods pretty clearly.

So I won't talk about getting in the plane but rather about getting out. Unfortunately, airline companies don't really have any kind of control over the passengers so the process is rather chaotic. Let's examine how it work:

People at the front row of the plane get up first and leave, followed by the people in the second row, third row, etc. until the plane is empty. This is roughly how it goes. The big problem here is the presence of overhead bins. Let's use a plane with 3 seats on each side of the single aisle as an example. Only the two persons on the aisle seats of each row can actually get up and access the overhead bins. What that means is that when it's (finally) time for your row to leave the plane, four people will have to take the time to take their carry-on luggage from the overhead bins.

Since the aisle space is the bottleneck here, every second you block it is a second that everyone behind you lose. When you're in the last row you lose a lot of time because of that! Why is that happening? It's pretty easy to understand. If it takes you five seconds in the aisle to take your stuff out, that's only five seconds to you, even if it might be multiplied by the hundred people waiting behind you. I guess it's the "I waited this long, now it's my turn, I'll take as much time as I want" phenomenon we can see in whatever other situation where there is a long wait time. Once you're not waiting anymore you don't realize lots of other people are still waiting.

What can you do to help? Well, if you're in the aisle seat, offer to bring down other people's luggage from the bins. That should help tremendously. Otherwise, when it's your turn, try to avoid staying immobile in the aisle, try getting your stuff and then go back to a seat if you need to adjust your bag or whatnot.

Tuesday, January 29, 2008

Wait for the bus or walk?

Another bus related question.

You're waiting for the bus, it's late, it feels like it will never come. Inaction is killing slowly making you angry, you wonder: should I just walk instead? Unsurprisingly, you should choose the lazy option and wait, which is going to be optimal in almost all cases.

This is what three mathematicians have found out in this paper.

Thursday, January 3, 2008

Optimizing your nutrition

I used to be completely oblivious to what I ate. I would just eat whatever I wanted, whenever I wanted and never really worry about it. I have good reasons though, I'm 5'10 and 130lbs, I don't really have anything to worry about.

But this all changed last March when I went to the Computer Science Games for the second straight year. The CS Games, as it's called, is a week-end long competition where teams composed of undergrads from various universities fight in computer science related contests. One of the competition involved generating the best diet possible for an athlete, given a list of food, with their associated nutrition information, and a set of guidelines. I unfortunately don't have the exact problem anymore but the rules were of the type:

  • You need 2000 calories, you will lose one point for every calorie under or over that.
  • You lose 100 points for every gram of trans fat.
  • You lose 100 points if you don't have at least one green vegetable.
  • You need exactly 60g of sugar and will lose 5 points for every g under or over.
  • You need 100% of the daily intake of Vitamin A
  • etc.
It's a typical example of what is called combinatorial optimization. This is when I realized that every thing you put in your mouth can be categorized and transformed into a set of numbers. Ever since then I've been semi-obsessively looking at every nutrition label before eating something. Not because I'm worried about my health or my weight, but simply because now that I know they're there it's difficult to ignore them.

Since there are people out there with degrees in nutrition, I won't try to pretend actually knowing a lot. But here are the tips I picked up in the last nine months or so.

  1. Make sure to look at the serving portion. Since every number is per portion, if a company decides that their juice box has two portions in it, they can effectively halve everything, and some do.
  2. Saturated fat, bad. Trans fat, BAD!
  3. People eat way too much sodium, especially if most of what you eat come from a box or a can.
  4. You need a lot of physical exercise to burn calories so don't think you can eat as much as you want and you'll just work it off. It'll take almost an hour of jogging to burn a cheeseburger. Or if you go running for 30 minutes, come back and drink a can of soda to cool off, you've just "wasted" half your exercise.
  5. There is an awful lot of sugar in soda, about 10 teaspoon of it. Compare that to how much sugar you put in your coffee. I used to drink a lot of Pepsi, not anymore.
  6. Same thing with beer, lots of calories in them. If you drink 24 beers on top of your regular diet, you will gain a pound.

Health Canada has a guide to help you in understanding the labels.

P.S. For the record, we solved the problem by writing an algorithm to find a very good solution, but got a bad score because we stupidly thought a "green pepper" was a "green vegetable". Turns out the color isn't the only thing that makes a vegetable green...