Sunday, April 23, 2017

End of The World

As I sat bewildered and amused, I knew it was a story that I had to be save for her wedding reception.  Next to me, my older daughter was sobbing inconsolably, "why does it all have to end this way?"

Rewind ten minutes. It was not a conversation that was supposed to go like this.

You see, my dad is absolutely fascinated by the night sky. I thought I'd play the role of a good son and father, by testing whether talking about space would ignite my daughter's interest in the subject. Perhaps, next time they met, they could obsess over a shared interest.

Me: Do you know the name of our galaxy, M.?
M.: Of course, the Milky Way!
Me: Good! They teach you good stuff in school. Now, harder question; do you know which galaxy is right next to ours?
M.: No, which is it, Baba?
Me: Andromeda. And I bet you haven't heard this. Billions of years later, Andromeda and the Milky Way are going to smash into each other. It is going to be spectacular!

M.: (troubled) Can't we do anything to stop it?

I cracked open a laptop, and fired up a browser.

Me: Look this is Tallahassee. This is Florida. This is the Earth. This is the solar system (zooming out each time). This is the Milky Way, and this is Andromeda. We are too tiny to do anything meaningful.
M.: (definitely worried) What does that mean? Does it mean we all die?
Me: (scoffing) Oh, don't worry about that. This is going to happen after BILLIONS of years. We will all be dead long before that. In fact, perhaps the Earth will be gone before that.
M.: What do you mean, Baba?
Me: You know how the sun is a star, right?  Like all stars, it shines by burning gas. It has tons of gas, kinda like Baba's tummy. But once it runs out of most of that gas, it might expand to about 3 times its size, and gobble up Mercury, Venus, and probably Earth.

I noticed tears streaming down her cheeks. I had to console her. And I had do it fast.

Me: But don't worry. Dont' worry! This is not going to happen for  BILLIONS of years more. We will all be gone by then.
M.: (now sobbing inconsolably) why does it all have to end this way?

After a few minutes, she regained her composure. I was debating whether it would be tone-deaf to talk about the real things to be scared of, like global warming, or pandemics, or..., when she interrupted me with a plea.

"Baba, can we please not talk about space, anymore?"

Tuesday, April 11, 2017

Strogatz and Art of Mathematics

For some reason, these Steve Strogatz' columns from 2015 on the "Art of Mathematics" have resurfaced.

Here are two blog posts, which explains the origins, inspiration, and mechanics.

The associated website is chock full of useful resources and ideas designed to help liberal arts students appreciate the art and joy of mathematics.

Thursday, March 30, 2017

Statistics and Gelman

Russ Roberts had a fantastic conversation with Andrew Gelman on a recent podcast. It covered a lot of issues and examples, some of which were familiar.

A particularly salient metaphor "the Garden of Forking Paths" crystallized (for me) some unintentional p-hacking by people with integrity.
In this garden of forking paths, whatever route you take seems predetermined, but that’s because the choices are done implicitly. The researchers are not trying multiple tests to see which has the best p-value; rather, they are using their scientific common sense to formulate their hypotheses in reasonable way, given the data they have. The mistake is in thinking that, if the particular path that was chosen yields statistical significance, that this is strong evidence in favor of the hypothesis.
This is why replication studies in which "researcher degrees of freedom" are taken away have more reliable scientific content. Unfortunately, they are unglamorous. Often, in the minds of the general population, they do not replace the flawed original study.

Gelman discusses numerous such examples on his blog. These include studies on "priming" and "power poses" that have failed to replicate. Sure there is the element of schadenfreude, but what I find far more interesting is the response of scientists who championed a theory react to new disconfirming data. For instance, Daniel Kanheman recently admitted that he misjudged the strength of the scientific evidence on priming, and urged readers to disregard one of the chapters devoted to it in his best-seller "Thinking Fast and Slow". Similarly, one of the coauthors of the original power poses work, Dana Carney, had the courage to publicly change her mind.

That is what good scientists do. They update their priors, when new data instructs them to do so.

This brings me to another health and nutrition story doing rounds on the internet. It suggests a 180-degree turn on how to deal with rising incidence of peanut allergies. Instead of keeping infants away from nuts, it urges parents to incorporate them into early, and often. I haven't looked at the original study carefully, but my instincts on retractions and reversals of consensus tells me to take the findings seriously.

Monday, March 27, 2017

Logarithms of Negative Numbers

A plot of log(x) looks something like the following:

As x decreases to zero log(x) approaches negative infinity. For negative values of real x, the log function is undefined. For example, consider the following numpy interaction:

>>> import numpy as np
>>> np.log(1)
>>> np.log(-1)
__main__:1: RuntimeWarning: invalid value encountered in log

If I try to do the same in Octave, I get something different, and interesting.

octave:1> log(1)
ans = 0
octave:2> log(-1)
ans =  0.00000 + 3.14159i

The answer makes sense if we expand the scope of "x" from real to complex. We know Euler's famous identity, \(e^{i \pi} = -1\). Logarithms of negative numbers exist. They just exist in the complex plane, rather than on the real number line.

Octave's answer above just takes the logarithm of both sides of Euler's identity.

We can make python behave similarly by explicitly specifying the complex nature of the argument. So while log(-1) did not work above, the following works just as expected.

>>> np.log(-1+0j)

For x < 0, if we plot the absolute value of the complex number, then we get a nice symmetric plot for log(x).


  • In matlab, the command reallog is similar to np.log

Thursday, March 23, 2017

Housel on Writing

Morgan Housel is one of my favorite writers on the subject of economics and finance. He offers three pieces of writing advice in this column.


1. Be direct
2. Connect fields
3. Rewrite

Tuesday, March 21, 2017

Try a Pod

I am an avid podcast listener; over the past 6 years, they have enriched commutes, workouts and chores, immeasurably. There has been a concerted call to evangelize for the platform ("try a pod") in the past few weeks. In 2013, I already shared what I was listening to then. Podcast that I currently follow:

  • BackStory
  • My History Can Beat Up Your Politics
  • Hardcore History with Dan Carlin
  • CommonSense with Dan Carlin
  • Revisionist History
Science and Tech
  • Radiolab
  • Skeptics Guide to the Galaxy
  • Science Vs
  • a16z
  • Above Avalon
  • Full Disclosure
  • Note to Self
  • Recode Decode
  • Rationally Speaking
  • Reply All
  • 50 Things That Made the Modern World
  • Snap Judgement
  • The Moth
  • Criminal
  • This American Life
  • Found
  • 99% Invisible
  • The Allusionist
  • And Eat it Too!
  • A Way with Words
  • EconTalk
  • Five Good Questions
  • FT Alphachat
  • How I Built This
  • Invest like the Best
  • The Knowledge Project
  • Masters in Business
  • Rangeley Captical Podcast

  • Audio Dharma
  • Philosophize This
  • Educate
  • Commonwealth Club of California
  • Fareed Zakaria GPS
  • Frontline audiocast
  • In Our Time
  • Intelligence Squared
  • Intelligence Squared US
  • Left Right and Center
  • Please Explain
  • More Perfect

Tuesday, March 14, 2017


1. Doug Natelson's compilation of "advice" blog-posts (nanoscale views)

2. Are Polar Coordinates Backwards? (John D. Cook)

3. Learning Styles are baseless? (Guardian)

4. 5 Unusual Proofs (PBS YouTube Channel)

Friday, March 10, 2017

QuickTip: Sorting Pairs of Numpy Arrays

Consider the two "connected" numpy arrays:

import numpy as np
x = np.array([1992,1991,1993])
y = np.array([15, 20, 30])

order = x.argsort()
x     = x[order]
y     = y[order]

x = array([1991, 1992, 1993])
y = array([20, 15, 30])

Wednesday, March 8, 2017

Perverse Incentives and Integrity

Edwards and Roy write about scientific integrity in the face of perverse incentive systems (full citation: Edwards Marc A. and Roy Siddhartha. Environmental Engineering Science. January 2017, 34(1): 51-61. doi:10.1089/ees.2016.0223.)

Here is a table from the paper, which grapples with incentives and unintended consequences.

Worth a look!

Monday, February 27, 2017

Not so Golden?

We discussed Golden section search method for optimizing functions in 1D last week. Naturally, we had to talk about the golden ratio (GR) and its appearance in the cultural zeitgeist.

However, there are many misconceptions/misunderstandings about the golden ratio, as researched in this eminently readable 1992 article by George Markowsky (pdf). For example:

  • neither the great pyramid of Cheops, nor the Parthenon, were designed to conform to the GR
  • da Vinci did not use the GR in his paintings
  • the golden rectangle is not obviously the most aesthetically pleasing rectangle
  • connection with the dimensions of the human body are exaggerated,
  • etc.

Keith Devlin explores this misconception in this video:

Saturday, February 25, 2017

Interesting Links

1. The Overpopulation Myth (video)

2. Is Bill Belichick lucky? (Russ Roberts on medium)

3. Math and the Good Life (quanta)
If I learn mathematics and I become a better thinker, I develop perseverance, because I know what it’s like to wrestle with a hard problem, and I develop hopefulness that I will actually solve these problems. And some people experience a kind of transcendent wonder that they’re seeing something true about the universe. That’s a source of joy and flourishing.
4. Indian snake catchers in Florida!

Thursday, February 23, 2017

Split a Text File using csplit

Suppose you have a large "sectioned" text file which looks like the following

> cat bigfile.txt



csplit bigfile.txt /data/ {*}

splits it into a bunch of files xx0, xx1, xx2, ..., where each of the "xx" files holds a section. Thus,

> cat xx1

and so on. Can be just the quick tool you need at times.

Friday, February 17, 2017

Google N-Grams for Keywords in Journals

Google Ngram Viewer allows us to visualize popularity of keywords as a function of time. It uses books archived on Google Books as its corpus.

However, it doesn't work quite as well on some domain specific scientific keywords.

The best tools for this is Web of Science, if you are lucky enough to have institutional access to it.

Once you search a keyword, scroll to the bottom left and look for the "Analyze Results" button. Then choose "Publication Years" in the "Rank the records by this field" window.

Here I looked for "tube model", which is a popular model in polymer melt dynamics.

You can export the result and play with it.

Thursday, February 9, 2017

QuickTip: Reducing PDF Size using GhostScript

The command is:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf


Wednesday, February 1, 2017

Neat Little Integral Trick

John D. Cook writes about a useful integration trick by rewriting trigonometric functions as complex variables. He recasts the integral \[\int e^{-x} \sin(4x) dx,\] using \(e^{ix} = \cos x + i \sin x\) as the imaginary part of \[\int e^{-x} e^{4ix} dx.\]

The derivation is cleaner (no integration by parts), and you don't have to remember any trig formulae. You can do pretty much any trig integral:\[\begin{align} \int \cos x dx & = \int e^{ix} dx \\
& = e^{ix}/i \\ & = -i e^{ix}. \end{align}\] The real part of the last expression is \(\sin x\).

Saturday, January 21, 2017

The Post-Statistics World

A wonderful long form essay by William Davies, "How statistics lost their power – and why we should fear what comes next"
The declining authority of statistics – and the experts who analyse them – is at the heart of the crisis that has become known as “post-truth” politics. And in this uncertain new world, attitudes towards quantitative expertise have become increasingly divided. From one perspective, grounding politics in statistics is elitist, undemocratic and oblivious to people’s emotional investments in their community and nation. It is just one more way that privileged people in London, Washington DC or Brussels seek to impose their worldview on everybody else. From the opposite perspective, statistics are quite the opposite of elitist. They enable journalists, citizens and politicians to discuss society as a whole, not on the basis of anecdote, sentiment or prejudice, but in ways that can be validated. The alternative to quantitative expertise is less likely to be democracy than an unleashing of tabloid editors and demagogues to provide their own “truth” of what is going on across society. [...]
In many ways, the contemporary populist attack on “experts” is born out of the same resentment as the attack on elected representatives. In talking of society as a whole, in seeking to govern the economy as a whole, both politicians and technocrats are believed to have “lost touch” with how it feels to be a single citizen in particular.
Some thoughts:

Some clear-cut questions can be adjudicated, purely based on observation, measurement, and statistics. For example, "how far is the sun?", "what is the average life-span of a human?", etc. Other questions, especially those that arise from inherently complex systems, often resist simple interpretation of numbers. These include questions about nutrition, ecology, macroeconomics etc. It is difficult to interpret measurements and facts, without an underlying theory or story.

Such numbers need compelling narratives to hang on. In such cases, a single counter-example doesn't disprove a thesis: a chain smoker who lives to be 100, doesn't disprove the claim that smoking is bad for you. Likewise, good narratives need numbers to ground them (think any pseudo-scientific claim). 

Calculations and stories go together; it is not one or the other. It has to one and the other.

Friday, January 13, 2017

The Need for Narratives

Neal Koblitz writes in the Chronicle:
The common element in all of this is knowing how to tell a story. Contrary to popular misconceptions about science and technology, a good piece of technical work is not a disembodied sequence of formulas and calculations, but rather is part of a narrative that has a long plot line and a large cast of characters. [...] Story-telling is a fundamental part of being human, from the time we are little children.
I couldn't agree more. The ability to weave a compelling story through a presentation or journal article makes a truly memorable one stand out from the run-of-the-mill kind.

You should check out the rest of the opinion for why STEM majors need grounding in the humanities.

Tuesday, January 10, 2017

An Adventure in Active Learning

I decided that I finally wanted to give this flipped classroom thing a shot. When I found out that I was scheduled to teach a Matlab/Mathematica class, a couple of years ago, I figured it was ideally suited for this experiment.

I spent the previous summer thinking through the format, reimagining the material, and the pacing. The idea was simple.

There were excellent 15-minute videos on the Mathworks and Wolfram sites, which students would watch before class. They would take a quick, but super-easy, quiz at the start of every class to ensure that everyone watched the videos. We’d then spend class time doing actual modeling, programming, and discussing common pitfalls and misconceptions.

I was very excited at the start of the semester. If I were a student, I would have loved the class I put together. Without a doubt. That's what I thought!

The excitement drained away quickly.

About 1/3 of the class was super-engaged. They watched videos, they were active in class, and I felt that they truly got something out of the class. If all of my class did as well, I would have thought that the experiment was successful. Grudgingly though, I had to admit that this 1/3 would have mastered the subject, even if I did not show up to class.

The middle 1/3 tried to keep up. They were somewhat inconsistent. In some classes, they were very active, and in others, they struggled. Would they have done better in a traditional class? Who knows!

About 1/3 of the class did not watch the videos. Consistently. I exhorted them, unsuccessfully, to come see me after class, so that we could work on the gaps in their understanding. Class time was miserable for them. They hid behind the terminals, doing their homework, while the rest of the class was busy solving problems.

After about a month I realized I had completely lost them.

Overall, I felt terrible about the experiment. It failed.

I haven’t tried flipping my classroom, since.

I have tried to do several post-mortems to figure out what went wrong; if there was something I could have done differently to fix the problem I saw, fairly early on.

The whole process relied heavily on students doing their homework. I was open to them not getting all the material in the videos. We could discuss that stuff in class. That would have been wonderful.

But flipped classrooms are still relatively rare in my university. Their novelty meant that students hadn’t realized the importance of keeping up with assigned material.

This was an undergrad class. The distribution of “work ethic” is often wider than in grad classes. From my experience flipped classrooms can work well even with a wide distribution in ability, given relatively high appetite for hard work.

But, vice versa, is another story.