Monday, August 13, 2012

What can Brown do for you?

What can brown do for you? So goes UPS's slogan. The answer is, as the color suggests, shit. Take my case today: the estimated delivery time was before 10:30am and the actual time the guy showed up was 5:17pm! Of course no one was home by then. So I submitted a request to hold the package at the facility for pick-up. Then I thought maybe it would be better to have the package delivered to my doorman'ed building. The UPS website happily allowed me to enter the new address and my credit card information (for the $5 charge to change delivery address), and then apologized that it could not process my request, without giving any reason whatsoever. I called UPS customer service. Its automatic answering system gave me a list of options, none of which was what I wanted. So I said "what the fuck!". The dumb system surprisingly sensed my frustration and apologized for not understanding my choice, and repeated the same list of options. I took half a minute trying to decide whether to give up, at which point the system said "to speak with an agent, say agent". The agent was slightly more intelligent than UPS's website and its automatic answering machine, but only slightly. The fault, she explained, was my own, as I had already submitted a request to hold the package, thus I would not be allowed to submit yet a different request. It's unbelievable that a company like UPS should have such a poorly designed IT system. What can brown do for you? A ton of shit!

Friday, October 28, 2011

Resolve

A hope begotten at your sight, a resolve made in my mind,
A moth is destined for the flame, for the light.
Aware of the devastation ahead, yet
We no longer act in perfect logic.

Best not to have met, best not to have wished,
Only had we never loved one another.
Take not another step closer,
With every step we sink deeper.

'Tis time's mischief,
That separates our lives.
Longing for you, long is the way to you,
Bitter be the outcome,
This moment I want no escape.
The word "regret" will hurt the eyes.
Longing for you, long is the way to you,
The end is an inexorable mistake,
Onto this moment we hold,
We pray not for escape,
The word "regret" will hurt the eyes.
After your time and mine,
To our star-crossed love we resign.

一念执着

一眼之念 一念执着
注定就此飞蛾扑火
明知是祸为何还不知所措

最好不见 最好不念
如此才可不与你相恋
多一步的擦肩
就步步沦陷

是时间的过错
让我们只能错过
我多想念 你多遥远
早知道是苦果
这一刻也不想逃脱
可惜这字眼太刺眼
我有多么想念 你有多遥远
早知道结局是不能抗拒的错
停留在这一刻
不想逃脱
可惜这字眼太刺眼
两个世界 之后
只好 情深 缘浅




Monday, October 24, 2011

Why you should not bother to switch the envelope

You are presented with two envelopes, and are told that one contains twice as much money as the other. You are to choose one envelope and earn the money in it. You pick one envelope, and upon opening it, find that it contains y dollars. You have the option to keep that envelope, or to switch to the other envelope. Should you switch?

Here is the paradox: there is a 1/2 chance that the other envelope contains 2y dollars, and a 1/2 chance that it contains y/2. If you switch the envelope, your expected earning is 1/2 × 2y + 1/2 × y/2 = 1.25y, which is greater than y—your expected earning should you choose to stay with the current envelope. To earn more money, you should, therefore, switch.

It does not make sense, does it? Intuitively it should not matter whether you switch or not, because the envelope that you end up with is equally likely to be the one with more money or the one with less. So what is the logic flaw in the paradoxical argument above?

Let's say that one envelope contains x dollars and the other 2x dollars. When you pick one envelope, you have an equal chance of picking either one, i.e., P(y is x) = P(y is 2x) = 1/2. Should you choose not to switch, your expected earning is P(y is x) y(y is x) + P(y is 2x) y(y is 2x) = 1/2 × x + 1/2 × 2x = 1.5x. Here is an important subtlety: I've written y(y is ...) to denote the revealed amount y upon opening the envelope, in the two different events of y being either 2x or x; that amount is not the same for the two events! In other words, you cannot write the expected earning as P(y is x) y + P(y is 2x) y = y, because y is different in the two different events of "y is x" and "y is 2x"!

Should you switch the envelope, your expected earning is P(y is x) 2 × y(y is x) + P(y is 2x) 1/2 × y(y is 2x) = 1/2 × 2x + 1/2 × x = 1.5x, which is exactly the same as that should you keep your original choice.

The paradox is thus resolved by defining the right set of events ("y is x" and "y is 2x") and realizing that the revealed amount y is not a constant for these different events, but a function whose value varies between the events: y(y is x) = x, while y(y is 2x) = 2x.

Wait a minute, some may say. If you are told that the other envelope has equal probability of containing 2y or y/2 dollars, after you open the first envelope and find within it y dollars, you should obviously switch. So what is the difference between this setup and the original one?

Well, the two setups are quite different. To clarify their difference, it is helpful to consider how the second setup can be correctly implemented. A simple way is to begin with an empty envelope, and have another person put in it either 2y or y/2 with equal probability after you open the first envelope. No matter how it is implemented, the second setup requires making changes to the envelopes after the first envelope is opened, and the change depends on the amount in the opened envelope. So you will be playing a different game than the original one: in the original setup, the two envelopes are prepared beforehand and are not adjusted after your first pick.

The difference between the second and the original setup thus reveals the true fallacy of the paradox: it confuses the expectation of a two-step procedure with that of its second step alone. The two steps are: 1) pick one envelope out of the two, find out the amount within, 2) decide whether to keep it or switch to the other. Your expected earning depends on your action in the first step as well as on the second.

After opening the first envelope and finding y dollars in it, there are two possibilities for the initial set-up of envelopes: {y, y/2} and {2y, y}, and they are equally probable: P({y, y/2}) = P({2y,y}) = p. The expected earning, should you decide to switch on the second step, is

   P({y,y/2})[P(1st is y|{y,y/2}) y/2 + P(1st is y/2)|{y,y/2}) y
+ P({2y,y})[P(1st is y|{2y,y}) 2y + P(1st is 2y)|{2y,y}) y] = 2.25 p y

The expected earning of not switching on the second step is

   P({y,y/2})[P(1st is y|{y,y/2}) y + P(1st is y/2)|{y,y/2}) y/2] 
P({2y,y})[P(1st is y|{2y,y}) y + P(1st is 2y)|{2y,y}) 2y] = 2.25 p y

Again, there is no difference either you keep your pick or switch.

There is actually another subtlety. In the above analysis, I should have written P(y is x|y) and P(y is 2x|y) to denote the conditional probabilities that the picked envelope contains x or 2x, given that the revealed amount is y. I have taken P(y is ...|y) = P(y is ...), with the assumption that seeing what is in the envelope does not tell you any information on whether it is x or 2x. This is not necessarily true when you have additional information available. For example, if you know that neither envelope contains more than 1 million dollars, and your opened envelope contains over half a million dollars, you should definitely not switch. On the other hand, if your opened envelope contains 5 cents, and realistically you know that there is no way for the other envelope to have 2.5 cents (physically impossible), you should definitely switch since you now know for sure that the other envelope has 10 cents in it.

Sunday, October 16, 2011

Three Inches of Heaven

Stopping here, dare not to go on,
Stop the sorrows behind the curtains.
The farewell that you've handwritten on the next page,
Is beyond my power to refuse.
We've taken this road in much haste,
Holding onto false desires.
'Tis too late, 'tis beyond our patience,
To appreciate all that we've left behind,
Magnolia's scent cannot seal our wounds.
Look no more, the sun shine through the clouds in the sky,
Seek no more, the heaven of our rendezvous.
Lament no more, what you called fortune's constant reversals,
The three inches of sun shine that we cannot borrow.
Heaven is where our love has dominion.

三寸天堂

停在这里不敢走下去,让悲伤无法上演。
下一页你亲手写上的离别,由不得我拒绝。
这条路我们走得太匆忙,拥抱着并不真实的欲望。
来不及等不及回头欣赏,木兰香遮不住伤。
不再看,天上太阳透过云彩的光。
不再找,约定了的天堂。
不再叹,你说过的人间世事无常,借不到的三寸日光。
那天堂是我爱过你的地方。


Friday, January 07, 2011

The Modern Experience

The most joyful thing in life is to deal with people who know what they are doing. Take, for example, the dinner tonight at The Modern restaurant. The chef clearly knew what he was doing, for the food was impeccable. But the girl at the coat-check left the deepest impression. She was cuter than the average coat-check girl, with an engaging smile, and she definitely knew what she was doing. The six of us arrived in the evening after a day of heavy snow, and we each checked in our coat. I had a stack of paper with me, which I forgot to check in with my coat. We were seated, upon which I realized that my papers were an incongruous addition to the table. So I returned to the coat check, and asked the girl to keep my papers with our coats.

A fabulous meal later, I got my coat back. Neatly tucked in my coat pocket - my papers. The girl knew which coat was mine! The final score on The Modern - food: 9, coat check girl: 10.

Tuesday, December 28, 2010

Making sphinx work with postgresql

On my MacPro, PostgreSQL is installed in /Library/PostgreSQL/8.4/. To install sphinx and have it work with PostgreSQL, I need to configure it in the following way:

./configure --with-mysql --with-prefix=/usr/local/sphinx --with-pgsql --with-pgsql-includes=/Library/PostgreSQL/8.4/include/ --with-pgsql-libs=/Library/PostgreSQL/8.4/lib/


Friday, December 24, 2010

Getting postgis to work with django (and sphinx)

The django-sphinx package does not recognize the postgis backend; one needs to modify the /path/to/djangosphinx/utils/config.py and reinstall it to make the two work together. Add the following to _get_database_engine() in the config.py file:

def _get_database_engine():
...
elif 'postgis' in settings.DATABASES['default']['ENGINE']:
return 'pgsql'

If you are creating a database as the default superuser postgres but you will be connecting to the database as a different user (say chineseblade), it is necessary to grant the privileges to the user. Sadly, if you use template_postgis as a template in creating the database, you will need to grant accesses to the tables geometry_columns and spatial_ref_sys individually, in addition to granting privileges on the database itself. The procedure is

Log on to the database template_postgis as the superuser postgres, and issue commands:

grant select on table spatial_ref_sys to chineseblade;
grant all on table geometry_columns to chineseblade;

Log out, then log on the master database postgres, and create the database using the template:

create database mydb with template=template_postgis;
grant all privileges on database mydb to chineseblade;

Now in the settings.py in your project, set the database engine to 'django.contrib.gis.db.backends.postgis'. You are ready to go!