Saturday, February 25, 2012

5 hour energy

On my way back home yesterday, I heard this segment about the man behind the "5-hour energy" drink.



Turns out the guy is an interesting character called Manoj Bhargava, born in Lucknow, who now lives in a Detroit neighborhood. The company behind the drink had sales over 1.2 billion last year. From a Forbes article:
In eight years 5-Hour has gone from nowhere to $1 billion in retail sales. Truckers swear by it. So do the traders in Oliver Stone’s 2010 sequel to Wall Street. So do hungover ­students. It’s $3 a bottle, and it has made Bhargava a fortune.
He apparently spent 12 years in an ashram in the middle of his life
Bhargava says he spent his 20s traveling between monasteries owned and tended by an ashram called Hanslok. He and his fellow disciples weren’t monks, exactly. “It’s the closest Western word,” he says. “We didn’t have bowler haircuts or robes or bells.” It was more like a commune, he says, but without the drugs. He did his share of chores, helped run a printing press and worked construction for the ashram. Bhargava claims he spent those 12 years trying to master one technique: the stilling of the mind, often through meditation. He still considers himself a member of the Hanslok order and spends an hour a day in his Farmington Hills basement in contemplative silence.
Here is some more coverage.

Friday, February 24, 2012

Invertability of Random Matrices

Wikipedia says:
Singular matrices are rare in the sense that if you pick a random square matrix over a continuous uniform distribution on its entries, it will almost surely not be singular.
This means that if you use generate a random matrix (using matlab's rand function for example) the resulting matrix is likely to be nonsingular.

How likely? That depends on the size of the matrix.

To look at it slightly more quantitatively consider the well-known problem:
Consider an n by n square matrix A, whose entries are, with equal probability, either 0 or 1. What is the probability that this matrix is invertible (or nonsingular)?
Let us consider a slightly generalized version of the problem.

Consider again, a random square n by n matrix A, whose entries are restricted to the set of integers {-p, -p+1, ..., 0, ... p-1, p}. Each of the 2p+1 values are equally probable.

Thus, if p = 1, then the matrix A has entries {-1, 0, 1}.
  • What is the probability that this matrix is nonsingular?
  • What is the probability that this matrix is nondefective?

Sunday, February 19, 2012

Barry Schwartz and Efficiency

Psychologist Barry Schwartz (or the Paradox of Choice fame) pens in an interesting opinion on how to think about economics as a competition between efficiency and friction (and offers a quasi-defense of Mitt Romney's role at Bain Capital in the process).

On efficiency:
It may seem heartless to worship efficiency at any cost, including lost jobs and decimated communities, but it is important to understand that increased efficiency is the only way a society’s standard of living will improve. If your company raises your pay without becoming more efficient, it will have to raise its prices in order to pay you. This is true of all companies. And if all companies raise their prices to allow for higher wages, you will end up just running in place, with your higher wages exactly matched by the higher prices of the things you buy. It is only if your company and others find a way to pay you more without charging more that your living standard goes up.
On friction:
ALL these examples tell us that increased efficiency is good, and that removing friction increases efficiency. But the financial crisis, along with the activities of the Occupy movement and the criticism being leveled at Mr. Romney, suggests that maybe there can be too much of a good thing. If loans weren’t securitized, bankers might have taken the time to assess the creditworthiness of each applicant. If homeowners had to apply for loans to improve their houses or buy new cars, instead of writing checks against home equity, they might have thought harder before making weighty financial commitments. If people actually had to go into a bank and stand in line to withdraw cash, they might spend a little less and save a little more. If credit card companies weren’t allowed to charge outrageous interest, perhaps not everyone with a pulse would be offered credit cards. And if people had to pay with cash, rather than plastic, they might keep their hands in their pockets just a little bit longer.

Life is not as predictable as driving. We don’t always know where we’re going. We’re not always in control. Black ice is everywhere. A little something to slow us down in the uncertain world we inhabit may be a lifesaver.

Wednesday, February 15, 2012

Koodle: A trip

Koodle is a tiny hamlet (about 15 families, give or take), situated on the backwaters of the river Sharavati, that my maternal grandmother once called home. I have many fond memories of the place and its people, from my childhood - many of which have no doubt been embellished by the usual romanticism associated with good memories from bygone times.

This past December, I revisited Koodle, after a really long time.
Signboard saying Koodle in Kannada
They say no man visits the same river twice, because it is not the same man, and it is not the same river. 

Koodle is definitely not the same. It has continuous electric power, internet, a western-style toilet etc. (all of which my daughter appreciated!). A few familiar people and voices have disappeared, while the ones that remain sound older, and wiser.

The soul of the place has not changed - it is still stuck in some strange time capsule. The raw beauty of the place and its people is still palpable. The vast forests of coconut trees are still glorious. They looked more impressive in person, than in my recollections.

A view from the hilltop
My uncle (who lives in the old house) is still the same old bundle of limitless energy. Just like old times, he took us places, and showed us amazing things. We went on a walk by the river, late at night. He showed us how to fish with only a flashlight. (There is a species of fish that becomes motionless when you flash a light on it like a deer. You can then scoop it out with a butterfly net.)
My uncle Anandu seen with his ancient rifle
Speaking of fish - we ate so much!  My aunt, a tireless hostess, kept churning out amazing stuff from the kitchen.
Backwaters
There are very few pleasures in life that can rival eating fish for dinner - fish - that were alive and well during lunch time.

We had an amazing time!

Sunday, February 12, 2012

Links

1. Why do Zebras have stripes?: BBC Nature reports on a possible explanation.

I am happy to note the skepticism expressed in the last part of the report:
"Above all, for this explanation to be true, the authors would have to show that tabanid fly bites are a major selection pressure on zebras, but not on horses and donkeys found elsewhere in the world... none of which are stripy," he told BBC Nature. 
"[They] recognise this in their study, and my hunch is that there is not a single explanation and that many factors are involved in the zebra's stripes.
2. Trent at the Simple Dollar has a handy list of 75 things to watch on Netflix.

3. How good do you think you are at Matlab? Ask Cody.
Cody™ is a MATLAB game that challenges and expands your knowledge of MATLAB. It is a web service provided to the community in which you sharpen your programming skills by solving problems and interacting with the community. You can comment on any problem or solution and learn from solutions provided by others. Or you can challenge the community by contributing problems that you devise.

Friday, February 10, 2012

EPS figures: Embedding Fonts

Many journal publishers, including AIP, now demand EPS figures with fonts embedded. If you have Adobe Acrobat, then this is a trivial issue.

But Acrobat is not free.

[Side Note: Most of my figures for journal articles come from two programs: Inkscape for schematics, and Grace for plots. Inkscape supports embedding fonts in EPS directly. Grace currently does not (v5.1), but will do so in the near future (apparently v5.99 already has it).]

But here let us assume you have a generic EPS file which does not have fonts embedded. The process described here (which seemed to satisfy AIP) involves converting the EPS to a PDF, embedding fonts, and then converting back again.

But first, how would you find out whether your fonts are embedded? There are at least two ways. But first you need to convert the EPS to a PDF.

epstopdf unembed.eps [creates unembed.pdf]

Once you have a PDF you can:

(i) pdffonts unembed.pdf: On the particular file I am working on I get:

name           type         emb sub uni object ID
-------------- ------------ --- --- --- ---------
Times-Roman    Type 1       no  no  no       8  0
Symbol         Type 1       no  no  no       9  0
Times-Bold     Type 1       no  no  no      10  0


The key thing to note is the "no no no" under the "emb"(edded) field.

(ii) or, you can open the PDF in Adobe Reader. If you look at File -> Properties -> Fonts tab (in Adobe Reader 9 running on Linux), you will see something that looks like:
The key is you don't see the word "embedded" anywhere.

The next step is to embed the fonts in the PDF using some ghostscript black magic. You say (change only the filenames in red):

gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=embed.pdf -f unembed.pdf

Now you check whether fonts have been embedded in "embed.pdf".

pdffonts embed.pdf
 
name               type         emb sub uni object ID
------------------ ------------ --- --- --- ---------
KKRTRL+Times-Roman Type 1C      yes yes no       9  0
VMUCKG+Symbol      Type 1C      yes yes no      11  0
CNFCZN+Times-Bold  Type 1C      yes yes no      13  0


As you can see fonts have been "emb"edded. Or you can check it in Adobe Reader.


Finally, we convert the PDF back to EPS with:

pdftops -eps embed.pdf embed.eps

One caveat: As decribed here, you could have trouble (the ghostscript step may complain with some warnings, for example) embedding the font if your system doesn't have a mapping for it.
This usually happens with fonts like Helvetica, Times, and Symbol; these are proprietary font names, so their mappings aren’t found in most open source systems. But you can fix this problem, as described in this excellent font reference, by replacing the font names with their open-source equivalents:

Replace proprietary font names with their open-source equivalents. Since .eps is a text format, you can just open the .eps file in a text editor and search/replace the font names. Markus Neteler makes this even easier with a handy bit of sed:

cat b4unembed.eps | sed 's+Times-Bold+NimbusSanL-Bold+g' |\
sed 's+Times-Roman+NimbusSanL-Regu+g' |\
sed 's+Times+NimbusSanL-Regu+g' |\
sed 's+Helvetica-BoldOblique+NimbusSanL-BoldItal+g' |\
sed 's+Helvetica-Oblique+NimbusSanL-ReguItal+g' |\
sed 's+Helvetica-Bold+NimbusSanL-Bold+g' |\
sed 's+Helvetica-Bold-iso+NimbusSanL-Bold+g' |\
sed 's+Helvetica+NimbusSanL-Regu+g' |\
sed 's+Helvetica-iso+NimbusSanL-Regu+g' |\
sed 's+Symbol+StandardSymL+g' > unembed.eps

Wednesday, February 8, 2012

Layers in Inkscape

A very handy tutorial on how (and why) you should use layers in Inkscape.


Personally, I find layers handy in three situations:
  • when there are too many objects in the illustration, I find myself inadvertently clicking on the wrong ones. Controlling layers can make some objects unclickable, while still being viewable.
  • when I want to experiment with an illustration without messing up the original. Sure, I could save a copy, and work on a new copy, but layers provide a more natural solution.
  • when I am making multiple schematics that share most of the illustration. Of course, I could save each incremental difference as a new drawing, but again - layers allow me to do that in a more economical fashion. Also if I decide to make some changes to the "shared part" of the illustration, I don't have to go about changing it in a dozen different files.

Monday, February 6, 2012

Links

1. What is 2^3^4: Depends on who you ask (via Walking Randomly)!

2. Nice quote (via Simple Dollar)
First of all, if it’s on your mind, your mind isn’t clear. Anything you consider unfinished in any way must be captured in a trusted system outside your mind, or what I call a collection bucket, that you know you’ll come back to regularly and sort through. – David Allen
3. "What should I read next?", based on the last book I read.

4. An inspiring video:


Wednesday, February 1, 2012

Obama on Education

Diane Ravitch points out the hypocrisy in President Obama's speech, and his actions (via Race to the Top).
 I don't know about you, but I am growing convinced that President Barack Obama doesn't know what Race to the Top is. I don't think he really understands what his own administration is doing to education. In his State of the Union address last week, he said that he wanted teachers to "stop teaching to the test." He also said that teachers should teach with "creativity and passion." And he said that schools should reward the best teachers and replace those who weren't doing a good job. To "reward the best" and "fire the worst," states and districts are relying on test scores. The Race to the Top says they must.
Deconstruct this. Teachers would love to "stop teaching to the test," but Race to the Top makes test scores the measure of every teacher. If teachers take the President's advice (and they would love to!), their students might not get higher test scores every year, and teachers might be fired, and their schools might be closed.

Why does President Obama think that teachers can "stop teaching to the test" when their livelihood, their reputation, and the survival of their school depends on the outcome of those all-important standardized tests?
Anthony Cody blogs about a similar Jekyll and Hyde situation:
In a town hall meeting hosted by Univision, President Obama was asked by a student named Luis Zelaya if there could be a way to reduce the number of tests that students must take.
His answer was superficially reassuring, but underneath, rather alarming. He replied: 
"... we have piled on a lot of standardized tests on our kids. Now, there's nothing wrong with a standardized test being given occasionally just to give a baseline of where kids are at.

Malia and Sasha, my two daughters, they just recently took a standardized test. But it wasn't a high-stakes test. It wasn't a test where they had to panic. I mean, they didn't even really know that they were going to take it ahead of time. They didn't study for it, they just went ahead and took it. And it was a tool to diagnose where they were strong, where they were weak, and what the teachers needed to emphasize.

Too often what we've been doing is using these tests to punish students or to, in some cases, punish schools. And so what we've said is let's find a test that everybody agrees makes sense; let's apply it in a less pressured-packed atmosphere; let's figure out whether we have to do it every year or whether we can do it maybe every several years; and let's make sure that that's not the only way we're judging whether a school is doing well."
What is he thinking? Does he not see the disconnect between his words and policies? Should the Department of Education be abolished?