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!

Sunday, July 25, 2010

Death of a dreamer

What happens when a man dies in his own dream? Does he wake up or does he start another dream? It is one of the intriguing questions posed by the movie Inception. I have come close to dying in my own dreams, but I have always managed a narrow escape. This makes me think that death to oneself in a dream is something that simply does not happen. Our survival instinct may have diffused into our subconscious so that even in a dream, we protect ourselves from the ultimate self-destruction.

If you have experienced death in your dreams, please leave a comment here.

Monday, March 22, 2010

Obama Care, Not Even Wrong

The health care bill passed on Sunday, March 21st, 2010. A historic moment. It will be interesting to observe its consequences in the next decade, a potential gold mine for economists.

On the following Monday I had a lunch conversation with a colleague, and the issue of health care was briefly brought up. My colleague said that he just could not understand why anybody could have opposed the bill, why anybody would think that universal health care could be a bad thing. I was quite surprise by that statement, coming from a highly educated intellectual. Because nobody thought that universal health care was a bad thing, in the sense that it was morally unjustified. People opposed it for economical reasons. People opposed it because they had not been convinced that the benefit to the nation would outweigh the economic cost. My colleague's comment just made me realize that some supporters of the health care bill had only been considering the bill on moral righteousness, not on economical feasibility.

When I pass by a homeless person on the street, I also feel the moral obligation to help. Everyone should be entitled to a roof over the head, as much as everyone should be entitled to care in sickness. But there is no legislation for universal housing.

New York City has aggressively cut its subway services. Now I often wait twice as long for a train as before. No one could have thought that cutting subway service was a good thing. But sometimes it is the fiscally responsible thing to do. Policy making is not so much about doing the morally right as about setting the right priorities, and investing the resource where it will benefit the society the most.

There are many things that should be deemed universal rights, the "good things", but in reality are not available to everyone, for the simple reason that there is not enough of it to share. It seems strange to me that some legislators are arguing the health care bill on the moral ground: "If you think it is right, you gotta help us finish the fight." That seems like sports trash talk, not a cool headed argument. The morally correct is not always economically right.

If anything, better education for everyone makes more sense than health care for everyone. After all, people don't fall sick often, and most minor ailments heal by themselves. Poor education, on the other hand, hurts a person for life, day in, day out. A better education is not only essential to maintain United States' competitive edge, but it will also better equip the Americans to evaluate the legislative bills more rationally, instead of being swayed by politicians' hot-headed rhetorics.

I kept wondering: if universal health care was such an obviously good thing, why was Massachusetts the only state in the nation that independently enacted it? Why did all the other states choose not to follow suit on their own and enact their own universal health care for their state citizens?

Even if we limit the debate entirely to the moral ground, I cannot fully justify universal health care, since it is not truly universal health care, but only health care for AMERICANS! Majority of the world's population live in poverty and do not have access to many basic life's needs. I personally detest any entitlement from a privileged birth, even though I accept it as a fact of life. But please do not use it as the basis of a moral argument. It is plain hypocrisy!

Obama called the passing of the bill "what change looks like". I am very disappointed. What Obama promised on his campaign was bipartisan politics. What I expected to see was a pragmatic approach to tackling the nation's most urgent problems, not the old ideological bigotry. The health care bill was passed without a single Republican vote. It was passed not because it was resoundingly convincing to the majority, but through insidious political manouvres that would surely anger its opponents and further divide this nation. If this is what change looks like, it is not the kind that I can believe in.

Friday, March 05, 2010

Cheaper expensive

As I strolled down the Madison Avenue, a sense of indignation assailed me on full scale. The display of excesses in the row of boutiques like La Perla, Oliver Peoples, and Breguet struck me as a manifestation of social inequality. Is there any justice that a bra, a pair of sunglasses, or a watch should cost so much that they are beyond the reach of ordinary hardworking Americans? Why is there not a legislative motion to rein in the cost of luxury goods, to make them universally accessible to all citizens of this wealthiest nation in the world?

A person with even the faintest turn of mind in economics, like me, can predict what such price restriction would do. There would be no more La Perla bras, no more Oliver Peoples sunglasses, and no more Breguet watches. So far as we want to keep luxury merchandise around, there is no way to drive down their prices, for the simple reason that price is not the paramount factor in the purchase of luxury goods. Luxury goods compete in other dimensions: quality, design, and brand recognition. The rich buy what they desire, not what is cheap.

For the same reason it will be all but impossible to rein in the cost of healthcare without sacrificing the quality of care. When we go see doctors, the cost of treatment is seldom on the top of our mind. Money is no good to anyone who is too sick to enjoy spending it. There is no financial incentive for the doctors not to prescribe the best - and often the most expensive - treatment, and there is little financial incentive for the patients to turn down a costly but presumably efficacious prescription.  Healthcare is analogous to luxury goods in that the providers compete not in price but in the quality and effectiveness of care. This may sound heartless - how can something essential such as physical well-being be compared to a Gucci coat or a Hugo Boss gown! But economics is a cold-blooded reptile that knows only incentives and no morals. So long as there is no incentive from either party to control the cost at the consumption end of healthcare, i.e., when the patient sees the doctor, driving down the cost will remain political hot air.

The only check on medical cost comes from the insurance companies, which employ an army of medical consultants to review the necessity of the prescribed treatments and deny the ones that are deemed wasteful. This practice, unfortunately and perhaps rightfully, is often vilified in the public media; denial of care is invariably described as an example of corporate greed of the health insurance industry. 

The only existing mechanisms to make patients more cost conscious are the deductibles and the annual ceiling in coverage. By making the patient share part of the cost for each treatment, the insurance companies quite effectively prevent wanton visits to the clinic and abuse of the medical insurance. With a spending limit each year, the patient is more likely to reject unconscionably expensive treatment, in order to save for another rainy day. Yet, effective as these measures are in fighting insurance fraud, they do little in controlling the average cost.

Last summer I had a horse riding accident, and I was rushed to the ER in a nearby hospital, in the affluent town of Huntington. In retrospect, I sustained only a minor injury: a horse kicked me just below my abdomen and to the left of my groin - the kick landed squarely where my cervical bone was the hardest and, even though a nail from the horseshoe penetrated three layers of clothing and cut a deep wound in the flesh, it did not reach the bone. I remained lucid throughout and felt no discomfort in my internal organs. Nevertheless, when the doctors prescribed two CAT scans and one X-ray, just to ensure that there was no internal trauma, I was in no position to refuse. Sure it did not feel like that I really needed them, but maybe the pain in the cut wound was obscuring signs of hidden internal injury. Was it not better to be safe than sorry? Who was I to say what diagnostics and treatments were rightfully called for? That was the doctors' job. 

The total bill came close to $30000, of which I had to pay a deductible of $450. I did not learn about the amount of the deductible during my ER visit, and had I known about this sizable deductible, most likely I would still not have said no to any of the prescribed procedures. It simply would not be worth saving $450 to risk permanent organ damage, or in the worst scenario, my life.

I too support the call to rein in the medical cost; I am simply skeptical of the proposals stemming from moral arguments. Conscience is never as effective in improving the world as sensible economic policies. The only solution to reduce the medical cost lies in instituting policies that will place economic incentives for either the doctors or the patients, or both, to be more price sensitive, right where and when the doctors treat the patients. I suspect that it will be the private sector who can do it better than the government. Sadly, whatever measure there is and will be, it is likely to be branded as the most evil of all greed: placing money in front of human lives.

Sunday, February 21, 2010

Dogs as pet and meat

From Roger Cohen's Op-Ed in New York Times, Dog Days in China:
Another noted a local saying: "when the dog meat is being simmered, even the gods become dizzy with hunger."
Growing up in China, I ate a lot of dog meat. It is more flavorful than lamb, a bit chewier, and quite delicious. In New York, my wife and I had a Cocker Spaniel, Tom. When it passed away several years ago, we buried it in our backyard instead of making it a stew. If today I travel to China and eat in a Chinese restaurant that legally serves dog meat, I will order it. There is no evolutionary reason not to. Tom will not know, or care.

I suspect that "the gods" - plural in the quote from New York Times - refer not to the Christian God, but to numerous Chinese deities. There are plenty of Chinese folklore in which a dog becomes a meal for its palindromic counterpart.

I love dogs very much, both as pets and as meat. It depends on whether they are sitting by my table, or on it.

The Pursuit of Happiness

The following immortal words of The Declaration of Independence are in peril of misinterpretation:
... that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty, and the pursuit of Happiness.
Note that it is the pursuit of Happiness - not Happiness itself - that is among the unalienable Rights. The Obama administration and the current Democratic Party seem to leave out that crucial word "pursuit", and they kowtow to Americans' sense of entitlement. Forgotten are J.F.K.'s words "Ask not what your country can do for you - ask what you can do for your country." Americans now want their happiness handed to them on a plate.

It is often asserted that the citizens of the welfare states, such as the Scandinavian countries, are happier, and that Americans are among the less happy in the world. The surveys may say so, but the immigration trends seem to point to the opposite - I personally know quite a few friends who came to the States from the Scandinavian nations. Do immigrants come to the United States in search of misery? That seems to violate the basic human instinct.

Some Americans will always be happier than others; that disparity will remain ubiquitous in this world. But the strength of the United States lies in its social mobility. Nobody is limited by his or her circumstance of birth; everybody is truly blessed with the equal and unalienable right: the pursuit of happiness.

Math in Tax

I just had my taxes done. As I reviewed my tax returns, I noticed the following description on how to figure the limit on itemized deductions (http://www.irs.gov/publications/p17/ch29.html):

If your itemized deductions are subject to the limit, the total of all your itemized deductions is reduced by the smaller of the following reduced by two-thirds:

  • 80% of your itemized deductions that are affected by the limit. See Which Itemized Deductions Are Limited , earlier, or

  • 3% of the amount by which your AGI exceeds $166,800 ($83,400 if married filing separately).

That is a mouthful, and the rule seems contrived! Who stipulated it? The numbers seem to come out of the blue without rationale. To a scientist, it borders on the absurd. It is analogous to defining the speed of light by saying that light travels at the speed such that in a minute it covers the distance of one billion times the height of the White House on the north side. Anybody care to point me to the origin of this rule?

To assist the Americans to figure their itemized deductions, the IRS publication includes a worksheet that breaks down the calculations step-by-step. Here are lines 9 to 12:

9. Enter the smaller of line 4 or line 8 9. 2,784
10. Divide line 9 by 1.5 10. 1,856
11. Subtract line 10 from line 9 11. 928
12. Total itemized deductions. Subtract line 11 from line 1. Enter the result here and on Schedule A, line 29 12. 141,212

Do you see that line 10 is completely superfluous? Line 11 really is simply line 9 divided by 3, and line 10 does not seem to be used anywhere else in the tax return. Is it simply an opaque layer to conceal the absurdity and arbitrariness in the tax code?

Here is how to figure the limit on itemized deductions, in layman's language, but for the arithmetically more adept:
If your itemized deductions are subject to the limit, the total of all your itemized deductions is reduced by the smaller of the following:
  1. 4/15 of your itemized deductions that are affected by the limit. See Which Itemized Deductions Are Limited , earlier, or
  2. 1% of the amount by which your adjusted gross income (AGI) exceeds $166,800 ($83,400 if married filing separately).
More concisely, if the total of your itemized deductions is smaller than 3/80, or 3.75%, of the amount by which your AGI exceeds $166800, your eligible deduction will be limited to (1 - 4/15 ) = 11/15 ~ 73.3% of your total deductions; otherwise (if you manage to list a lot of itemized deductions compared to your AGI), your eligible deductions will be the total deduction reduced by 1/100 (AGI - $166800), and since that reduction is a fixed amount, there lies your opportunity of tax evasion.