Monday, May 30, 2016

The Amazing Tadashi Tokieda

I enjoyed this experiment and explanation by Tadashi Tokieda (YouTube link if the video below doesn't play)

If you have some time to spend, you cannot go wrong with this playlist!

Friday, May 27, 2016

Intersection of Ellipses

I was recently pondering about the area of intersection of two ellipses. That is, given two ellipses with known shapes (semi-major and minor axes), centers, and relative or absolute orientation, find the area of intersection.

The general problem turns out to be far more complicated than the simpler problem of area of intersection of two circles.

In particular, as Hughes and Chraibi demonstrate (free preprint, paywalled paper), the number of intersections can be 0, 1, 2, 3, or 4. Eberley also has a nice writeup with derivations (pdf).

Luckily, a software implementation (C++) is available here on GitHub.

Monday, May 23, 2016

A Brief History of Runge-Kutta Methods

Butcher's "A History of Runge-Kutta Methods" contains a beautiful account of the early days of this now ubiquitous method for solving ordinary differential equations.

Carl Runge, a German mathematician and spectroscopist, toyed with the idea of improving upon Euler's simple time stepping approximation for solving ODEs. In a 1895 paper, he wrote three down three different "Runge-Kutta" schemes to solve a particular differential equation that arose in the study of atomic spectra.
He used so much mathematics in his research that physicists thought he was a mathematician, and he did so much physics that mathematicians thought he was a physicist.
Two other German mathematicians, Karl Heun and Martin Kutta made additional contributions. In 1900, Heun wrote down RK methods up to order 4. In 1901, Kutta extended it to order 5, and systematized most of the prior work. His contribution included the classical 4th order RK method, which is the ODE analog of Simpson's method for numerical integration.

Numerical Recipes has this to say about this century old algorithm:
For many scientific users, fourth-order Runge-Kutta is not just the first word on ODE integrators, but the last word as well. In fact, you can get pretty far on this old workhorse, especially if you combine it with an adaptive stepsize algorithm.
By 1925, Nystrom had extended and cleaned up most of the RK methods developed previously.

Over the years, higher order methods were developed, stability properties were studied, and implicit RK methods capable of solving stiff problems were developed.

Wednesday, May 18, 2016

Stung by A Ray!

Last weekend, I was at the beach, wading around in the shallow waters on a beach off of beautiful Florida's Gulf coast.

All of a sudden, I felt a swift, sharp, barb strike my right calf. I couldn't help screaming a non-family friendly synonym of "ouch!".

My instinct was to run away from the scene towards the beach. I noticed blood trickling out of a narrow gash, about a quarter of an inch long.

It turned out that I had been stung by a sting ray, although I did not know it at the time. The pain was excruciating, and lingered around for well over six hours.

Here's what I learned: (i) you should "shuffle" or "skate" along the sea; not "step" walk. When approached laterally, sting rays know how to get out of the way, and don't feel threatened, and (ii) douse the wound in really hot water, as soon (and for as long) as possible. The hot water breaks down some of the proteins in the venom, and dramatically reduces the pain.

Saturday, May 14, 2016

What I Learned Last Week

1. F is for Fiber: The Audacity of Google Fiber (recode)
Rick Usher has a favorite parlor trick. He recently showed it off over dinner with a friend’s family, who doesn’t have Google Fiber. Their teenage daughter was thumbing her iPhone, and Usher asked her to pull up her favorite YouTube clip. He told her to drag the cursor to the clip’s middle. "She literally jumped out of the chair, ‘Oh my God, it didn’t lag!’" he recalled.
2. Video Series of Differential Equations and Linear Algebra (mathworks)
Gil Strang has produced a MOOC-style video course on Differential Equations and Linear Algebra. I have added some videos about the MATLAB ODE suite. The series is available from the MathWorks Web site, MIT OpenCourseWare and several other popular sources.
3.  Our Glorious Broken Health Care System (malvasia bianca)
I didn’t have to pay a thousand dollars myself: my insurance has negotiated rates that are lower than the billed rates, and my insurance paid for a fair amount of what was left, so my bill was only about three hundred dollars. But there is no way that I would have paid three hundred dollars for a known-inaccurate test if I’d been aware of the price in advance; [...]

Sunday, May 8, 2016

Warren Buffett 90-10 Portfolio and the Kelly Criterion

When Warren Buffett was asked how he would ask his wife to manage their money after he was gone, his advice was simple.
My advice to the trustee could not be more simple: Put 10% of the cash in short-term government bonds and 90% in a very low-cost S&P 500 index fund. (I suggest Vanguard’s.) I believe the trust’s long-term results from this policy will be superior to those attained by most investors…
Can we try and understand this choice through the lens of the Kelly criterion, which we have explored in some depth in previous posts?


Suppose that returns \(r\) from the stock market obey a Gaussian distribution, with the mean \(\mu = 1.1\) and scale factor \(\sigma = 0.3\). Note that this \[r = 1 + \text{annual rate of return}.\] This choice essentially assumes average annual returns of 10% from the market, and anticipates typical swings (\(2\sigma\)) to lie between -50% and +70%.

We will play with some of these parameters later, but right now, they seem reasonable enough; so lets not fixate on them.

I will also assume that the worst possible return is \(r = 0\), which implies a return of -100%, which means everything is completely wiped out. This has never happened in the past, and it seems like a good bet that this will "never" happen in the future. Similarly, I will assume that the best possible returns are 300%. It seems like a reasonable cap.

So my annual returns are expected to be random variables drawn from a truncated normal distribution. Let's see what this would look like.

Kelly Criterion

In the Kelly criterion, the crucial expression to develop is the mean of the logarithm of the expected return.

In this case, the probability of obtaining a return of \(r\) is \[\mathcal{N}_{T}(r|\mu, \sigma, r_{min}, r_{max}) dr,\] where the subscript "T" reinforces the "truncated" aspect of the normal distribution.

If I wager a fraction \(f\) of my investment pot, then I should expect to end up with, \(1 - f + f r\), where I assume that the uninvested fraction is kept safe in cash, and earns 0%.

Thus I can write the logarithm of the pay off as:
\[\log S = \langle \log R \rangle = \int_{r_{min}}^{r_{max}}  \mathcal{N}_{T}(r) \log(1 + f(r-1)) dr\]  Let's visualize log S for this choice of \(\mathcal{N}_{T}(r)\).
Python codes used to generate these (and subsequent results) are at the end of this post.

The optimal allocation to the S&P portfolio using the Kelly criterion (by maximizing log S) is 82.8%, which is reasonably close to Buffett's suggested portfolio.


Let us consider three scenarios: (i) conservative (\(\mu = 1.05\), \(\sigma = 0.5\)), (ii) moderate (\(\mu = 1.08\), \(\sigma = 0.4\)), (iii) aggressive (\(\mu = 1.12\), \(\sigma = 0.3\)).

The optimal allocations for the conservative, moderate, and aggressive assumptions are approximately, 55%, 83%, and 100%, respectively.

If we assume a \(\sigma = 0.3\), then a 90% stock allocation corresponds to a \(\mu \approx 1.09\), or an expected 9% rate of return from the S&P.

Historically, the standard deviation of S&P returns has been closer to 0.2. I like to use a higher number because the histogram of the actual returns is not perfectly normal, and the tails have been fatter than one would expect from a \(\sigma = 0.2\).

Python Code

Wednesday, May 4, 2016

What I Learnt Last Week

1. Students! Make use of office hours. (Quartz)

2. Does fasting stave off disease? (Quartz)

3. Should you not get a PhD? (Atlantic)

4. How TED thinks you should speak in public (Business Insider)

5. Why exercise alone won't help you lose weight (Vox)

Monday, May 2, 2016

Traffic Modeling

Last week, I became momentarily frustrated with a particular research problem I've been grappling with for over a year and a half now. Fearlessly oversimplifying, I found that some objects moving in crowded environments slow down below their natural speed as the surrounding objects become fast enough.

The literature and models in my sub-sub-subfield weren't helping. So I thought I'd look at research in traffic modeling. From personal anecdote driving on interstate highways, I've noticed that when there are a few rash drivers swerving lanes and driving superfast, I tend to be more careful and slow down.

I didn't find exactly what I was looking for, but bumped into a bunch of "popular" resources, which I thought I'd archive for a closer look later.

1. Here is a provocative, readable but slightly flawed analysis on the physics of traffic jams
2. The principal claims of the article are contested by a ridiculously simple model here.
3. Wikipedia has an interesting overview of traffic simulation
4. A slightly more research oriented (but very readable) resource at MIT with plenty of links

The first two articles provide radically different ideas on how to treat traffic jerks. The first article (and some other published research) argue that a few rule-breaking mavericks help. The second link suggests that due to physical constraints anybody who cuts into the "line" ahead of you, delays your estimated time of arrival.