Friday, October 18, 2019

LaTeX: Cross-referencing between Different Documents

Problem: I have a manuscript TeX file (main.tex), and an independent supporting information file (si.tex). I was to cross-reference (using \label and \ref) items across the two files.

For example, I might want to reference figure 1 from si.tex in main.tex.

Solution: As this SO answer suggests, the answer lies in the CTAN package xr.

In main.tex, just include "si.tex" as an external documents, and all its labels become visible!

\usepackage{xr}
\externaldocument{si}

Thursday, October 17, 2019

Parameter Uncertainty in Numpy Polyfit

Say you want to fit a line to (x,y) data. With polyfit, you can say,

coeff = np.polyfit(x, y, 1)

With numpy 1.7 and greater, you can also request the estimated covariance matrix,

coeff, cov = np.polyfit(x, y, 1, cov=True)

The standard error on the parameters is the square-root of the diagonal elements

print(np.sqrt(np.diag(cov)))

This report referenced in the SO page is quite useful!

Monday, September 30, 2019

Learning Gaussian Processes

I've been studying up Gaussian process modeling for machine learning.

For someone seeing these concepts for the first time, I would recommend the following sequence based on my experience:

1. A Visual Exploration of Gaussian Processes

It hits the key points of what makes multinormal distributions special (conditionals and marginals are normal too!), and the visuals help build intuition.

1a. Gaussian Processes for Dummies

You might not need this, but I like this essay because it is jargon-free, and focuses on how to get things going. There is python code at the end, which you can play with.

2. Chapter 2 of Gaussian Process for Machine Learning

This "bible" is astonishingly well-written. If you are familiar with linear algebra and some statistics, this is a breezy read. Plus, all the important formulae and algorithms you see in different articles, are available here in one place!

3. If you like videos, then this YouTube lecture might be worth watching!

Thursday, August 22, 2019

QuickTip: Toggling to Previous View in PDF Readers:

I use Preview (on my Mac laptop) and Foxit Reader (on my Linux Desktop) to read PDFs.

While reading papers, I often find myself clicking on links to citations. This takes me to the reference section. After looking up the citation, I like to go back to the previous location on the paper (right before clicking on the link).

How to go back to the "previous view" isn't well documented.

In Preview, the short cut is "Cmd + [" and "Cmd + ]".

In Foxit Reader for Linux (v2.4 and above) the short cut is "Alt + Left Arrow" and "Alt + Right Arrow", respectively. 

Friday, July 5, 2019

QuickTip: Math Font in Matplotlib

Matplotlib (v2 and higher) uses "mathtext" to render math by default. It is quite capable, but I don't like the default font, and prefer the classic "Computer Modern" font.

You can fix this globally by modifying the rc file in your custom-style file (use the command matplotlib.get_configdir() to find location) by adding the line:

mathtext.fontset : cm

If you want to render all text using LaTeX (this slows down rendering somewhat), then use:

text.usetex : true


Wednesday, July 3, 2019

Snip Math

Mathpix Snip looks like an amazing tool.

You take a screenshot of some math and get it rendered in LaTeX.

The process as illustrated on their website:



It is available for download on all major OS.

Wednesday, June 26, 2019

Zero and Infinity

A triangle has three corners.

A pentagon has five. A decagon has ten.

As the number of corners becomes large, the polygon becomes more "circular".

When the number of corners is infinity, the polygon is a circle - a shape with zero corners!

Wednesday, June 19, 2019

Links

1. Stay in the Game: There is hope in humanity!

2. Kevin Simler's graphical essay on going critical

3. The force of Gilbert Strang

4. Strogatz's "Beauty of Calculus" Lecture

Tuesday, June 18, 2019

QuickTip: Linux Convert Color PDF to GrayScale

Using GhostScript (source). The first line sets name of output file ("output.pdf" here)

gs \
 -sOutputFile=output.pdf \
 -sDEVICE=pdfwrite \
 -sColorConversionStrategy=Gray \
 -dProcessColorModel=/DeviceGray \
 -dCompatibilityLevel=1.4 \
 -dNOPAUSE \
 -dBATCH \
 input.pdf

Wednesday, June 12, 2019

Second-Level Thinking

James Holzhauer's epic run on Jeopardy came to an end.


While the human drama around that is entertaining, one of the best pieces of analysis was this write up "Did James make the right Final Jeopardy bet?" on one of my favorite websites.

At one level, his explanation made perfect sense, and did play out in the way the leader (Emma) bet.

But here's the "she knows what he knows what she know's" second-ordered thought (what the author calls the "mindfuck" strategy).

But Emma could have figured out his thinking, and bet a smaller amount, ensuring she won regardless of whether she got the question right or wrong (essentially sealing her victory).

Of course, one could take this type of reasoning one or more levels higher.

Saturday, June 8, 2019

Hawk Attack

Yesterday, as I was hiking down a trail in Tom Brown park, I was attacked by a hawk.

Bizarre, I know!

For an instant, as I felt the scratching on my head, I thought an old twig had fallen off a tree. But my confusion was dispelled a nanosecond later, as I saw the hawk's wide wings swooshing right in front of my forehead. From there, it swooped up like a jet taking off on a runway, and perched itself on a nearby tree, watching!

The claws had inflicted a minor scratch, but nothing serious (I finished the remaining 3 miles of my hike). Later, I called the nurse, just to see if I should take antibiotics or tetanus shot.

To my mild surprise, she told me that I was up to date on my tetanus shots. She said "your chart says you had your last shot in 2016."

Ah! The sting ray accident, I remembered!

Thursday, May 30, 2019

QuickTip: Import Beamer Slides into Article

From here:

\documentclass[12pt]{article}
\usepackage[noxcolor]{beamerarticle}

Saturday, May 18, 2019

Trimming and Speeding MP3s

sox is a great command-line tool ("swiss army knife") for working with sound.

You can download it using apt-get or the software manager for your system.

Trimming a file is easy:

sox trim

sox fullsong.mp3 trimsong.mp3 trim 1:00 2:30

This trims a two and half minute portion of the file starting from the 1:00 minute mark.

Speeding up an audio file is also easy. To speed it up by 10%, use:

sox normalsong.mp3 fastersong.mp3 tempo 1.1

Thursday, May 9, 2019

The Beauty of Calculus

Here is a wonderful talk by Steve Strogatz at Yale.

It is based, in part, on his most recent book "Infinite Powers".

Saturday, May 4, 2019

Antifragile and Hormesis

So yeah, Nassim Taleb and Nate Silver are having a spat on Twitter on what probabilities mean. Unfortunately, Twitter a great medium for expressing outrage, not so much for persuasion.

Here is a more thoughtful take on Taleb's concept of Antifragility. Eric Falkenstein argues that it is an old idea repackaged in a shiny box.

While I concur with Taleb on most issues philosophically, I think the blog articulates what I have thought about most of NNT's big ideas (excellent marketing that oversell old ideas). As someone said, most of his work can be summarized as "shit happens; fuck you; because probability!"

Sunday, April 21, 2019

An Interactive Introduction to Fourier Transforms

Here is a great introduction to Fourier Transforms.

The focus is on developing a intuitive understanding for the decomposition of a signal into it component waves. You can draw different signals and "listen" to the contribution of the individual frequencies.

A good complement to this resource is this video from Grant Sanderson (3Blue1Brown).

There are numerous mathematical definitions of Fourier transforms. John D. Cook put together an exhaustive list, including pointers on how to move between the different definitions.

Thursday, April 11, 2019

Reshaping NumPy Arrays into Columns

$ x = np.arange(5)
$ x
array([0, 1, 2, 3, 4])

Two different methods:

$ x.reshape(-1,1)
array([[0],
       [1],
       [2],
       [3],
       [4]])

$ np.c_[x]
array([[0],
       [1],
       [2],
       [3],
       [4]])

Sunday, March 24, 2019

Mathy Links

1. Econophysics is a real thing (learnt about it here)

2. Why \(i^i\) is real!

3. Riffing on mistakes (John D. Cook)

Tuesday, March 19, 2019

Central Limit Theorem and Wisdom of Crowds

There is an illuminating correspondence between the central limit theorem and the notion of wisdom of crowds.

Informally, the central limit theorem says that the average of many independent trials is normally distributed around the true mean. A similar idea that animates the wisdom of crowds: consensus estimates obtained by aggregating or averaging the estimates of a number of individuals are superior.

The central limit theorem, while powerful, rests on three premises: the trials are independent, identically distributed, and have finite variance. If any of these three conditions are violated, then all guarantees are void.

In the context of the wisdom of crowds, the three premises loosely translate as follows: independent means that each trial (or individual estimate) does not know or care about other trials or estimates; identically distributed implies they are looking at the same underlying problem; and finite variance implies estimates are not so stupidly wild, that a single bad trial or estimate has an outsized effect on the average.

Joel Greenblatt presents a fascinating experiment in which he brought a jar of jelly beans into a class, and asked students to guess the number of beans, and to write it down on a piece of paper. The average of the student estimates was surprisingly close to the true number of the jelly beans in the jar.

But before he disclosed this fact to the class, he repeated the experiment. This time, instead of independently writing down their estimates, students were instructed to announce their guesses to the class. The estimates were no longer independent, and the consensus was way off.



Friday, March 15, 2019

QuickTip: LaTeX formatting for SymPy symbols

You can use LaTeX formatting to describe SymPy variables using:

Z, a, Zbar = symbols(r'Z, \alpha, \bar{Z}')

Tuesday, February 19, 2019

Ranked Choice Voting

Before I heard Radiolab podcast "Tweak the Vote", I hadn't heard of ranked choice voting.

Then, I instantly became a fan.

To see how it works, watch this video:


It is particularly good at weeding out extreme candidates in crowded fields, and in making sure protest votes are not too destructive.

It might also be the magic potion that helps our polarized nation heal, by improving the electability of centrist candidates.

Saturday, February 16, 2019

Data Science: Proceed with Caution

Vicki Boykis has a wonderful contrarian take on pursuing data science as a career.
Given that there are 50, sometimes 100, sometimes 200 people for each junior role, don’t compete with those people. Don’t do a degree in data science, don’t do a bootcamp []. 
Don’t do what everyone else is doing, because it won’t differentiate you. You’re competing against a stacked, oversaturated industry and just making things harder for yourself. 
It’s much easier to come into a data science and tech career through the “back door”, i.e. starting out as a junior developer, or in DevOps, project management, and, perhaps most relevant, as a data analyst, information manager, or similar, than it is to apply point-blank for the same 5 positions that everyone else is applying to.
What I like about her essay is that despite her "pessimism", she has valuable practical advice for someone still willing to jump into the waters.



Friday, February 8, 2019

QuickTip: Compare Altered Files in Two Directories

Use case: I copy a directory from my desktop to a USB, change several files while working on it on my laptop or home computer. Now I want to merge it back to the "master" directory on my desktop. I miss a "git diff" like command

On Linux:

diff --brief -r dir1 dir2


Friday, February 1, 2019

Open Textbooks

Here are links to some decent open textbook resources relevant for math and science.

Monday, January 21, 2019

QuickTip: Spell Check in LaTeX

On a previous blog, I wrote about how to set up "hunspell" as the default spell-checker in TeXMaker (my LaTeX editor of choice).

One can also spell check non-interactively from the command line. Get the linux utility hunspell using for example,

sudo apt-get install hunspell

Then, to get a list of flagged words that ignore latex tags:

hunspell -l -t myTexDoc.tex | sort

Drop the sort and "-l" flag check spellings interactively.

Wednesday, January 9, 2019

My Favorite Podcast of 2018

I listen to a lot of podcasts (2-3 hrs/day). They are my primary source of general knowledge.

It is hard to pick favorites, but I am going to do it anyway. The best individual podcast I listened to in 2018 was Rob from Heavyweight.
Rob remembers breaking his arm as a kid. But the rest of his family says it never happened. Did he break his arm? The answer will determine Rob’s sanity.
The podcast is hosted by Johnathan Goldstein. He sleuths around unfinished personal business that seems unimportant on the face of it. The wit, self-deprecation, and "lens" through which he tells his stories is unique.

Wednesday, January 2, 2019

The Other Side of Behavioral Bias

Jason Collins has an evolutionary take on how most behavioral biases "make sense" from an evolutionary standpoint.

Here is a writeup, and an (accompanying) presentation.

His blog which dwells on related issues is super-interesting.

I first heard him on the Rationally Speaking podcast.