Showing posts with label opinion. Show all posts
Showing posts with label opinion. Show all posts

Friday, November 30, 2018

Machine Learning and Behavioral Biases

Machine learning, using neural nets for example, helps us tease out hidden nonlinear correlations or patterns. A standard application is digitizing hand written numerals.

You train the model on a particular dataset, and test it on data that is previously unseen. If the training and test datasets are "similar", then the predictions of the learnt model will be good.

If the test data look nothing like the training data then the ML model will fail (e.g. train on Arabic numerals and test on Roman numerals).

Our brains were trained for thousands of years when we lived in the wild. Survival was key. A significant fraction of the model has been seared into our hardware.

Modern times look nothing like the training data for which our brains were optimized (saber-tooth tigers, food scarcity).

Most cognitive or behavioral biases originate in this mismatch between our training dataset and test dataset.

Monday, April 30, 2018

Matlab and Python

I use Matlab/Octave, quite a bit, for pre- and post- processing. About 3-4 years ago, I started dabbling with python, and gradually began using it to handle increasing parts of my workflow.

Last week, I chanced upon this webpage at Mathworks, which tries to argue why Matlab is superior to python. Here are the key advantages:
  • The matrix-based MATLAB language lets you express math directly: This is definitely true. Even now, when my work predominantly involves linear algebra, I sometimes use Matlab/Octave. The notation is natural and concise. But this is Matrix Laboratory after all.
  • Engineers and scientists deserve tools that fit the way they work. They shouldn’t have to adapt the way they work to fit their tools: It is true that Matlab documentation feels like it was written with engineers and scientists in mind, while python documentation has a computer-sciency feel. But, the other reasons bundled under this heading don't seem like they apply to me.
  • Proven MATLAB toolboxes provide the functions and capabilities you need. Period.: However, many toolboxes are have to be bought separately. The standard scientific python stack is fairly mature at this point. Even the library overall landscape for python is richer for python in my mind. It reminds of this xkcd cartoon.
  • MATLAB apps let you complete tasks more easily than with custom programming
  • MATLAB helps automate the entire path – from research to production
  • You can trust the results you get in MATLAB: I lumped these three together, because for some reason, they are non-issues for me. I enjoy prototyping in python. If I am hardware limited, and I have to squeeze performance, then I usually code in C++ or Fortran.

  • MATLAB runs your programs faster – meaning you can try more ideas and solve bigger problems: This is probably true, but ignores the existence of JIT compilation (Numba) or integrating with C++/Fortran (Cython) etc.
Some of the advantages of python over Matlab are listed here, here, and here. If I had to make an intermediate term prediction (10 years), I think python will become more popular than Matlab, among scientists and engineers.

Friday, August 5, 2016

On Writing

I overheard this quote from E. L. Doctorow on my favorite language podcast "A Way with Words"
[The act of writing is] “like driving a car at night: you never see further than your headlights, but you can make the whole trip that way.”
This beautifully-expressed thought touched a chord.

Usually when I begin writing, I have a rough notion of the ideas I want to communicate, but they are all tangled up like a ball of wool. The hope is to untangle the mess (think), cut redundant strands ("there is no writing, only rewriting"), and weave a sweater (a narrative) - to push the wool metaphor a bit.

Writing helps me think. It helps me learn. It helps me see new patterns in things I already know.

I have a simplistic theory on why writing works as a thinking and learning tool.

Our mind stores thoughts and ideas like my kids store their toys. They are all over the place.


A sentence or paragraph or story has a linear structure. It has a beginning, a middle, and an end.

In computer science terms, ideas in our mind are like graphs, ideas on paper are like queues.

The act of writing makes us examine the graph carefully, figure out the relevant or important links, and to project them into a one-dimensional (or quasi 1D) narrative.


Here's a game you can play with a kid that captures some of these thoughts.

Look at a map of the world showing different countries. These are like the ideas in your head. Each country borders other countries or water bodies (a graph).

Now pick any two countries, say US and Romania. Suppose the goal is find a path from the US to Romania, keeping track of the boundaries you cross. Perhaps, you want to minimize these crossings (or perhaps, you want to take the scenic route).

The act of figuring out an "optimal" path forces us to project the map of the world onto a queue. If we are attentive and lucky, we might learn new things.

Monday, April 25, 2016

The Problem with Facebook and Global Variables

A few years ago, Facebook was a source of joy in my life. I was actively rediscovering friends who had slipped away over time. Reconnecting, discovering what they were up to, and filling the gap between where we had left and found each other again, ushered in a sense of everyday freshness.

Over time, as a billion people got onboard, the rate of rediscovery diminished, and so did the excitement of eagerly checking new notifications. These days, most of my Newsfeed is cluttered with click-bait, unscientific bullshit, flashy headlines, and "Hallmark" greetings.

Every now and then, somebody posts pictures of an event or vacation, or something extraordinarily interesting. Those mark the high points; the rest is mostly junk.

I don't have the Facebook app on my phone. I've pretty much stopped contributing anything original myself like so many others. The other day I was thinking about why I stopped posting, and it occurred to me that my "friends" list contains contains a motley group of people who I know in very different ways.

We are different to different people. We are different to our kids, to our parents, our friends from undergrad, our professional colleagues, our bosses etc. This is not hypocrisy. This is human nature.

Trying to post something that does not offend at least one of the groups I belong to is either uninteresting or impossible.

Because of a conversation I had earlier today, I couldn't help noticing the parallels of this "context collapse", with global variables in programming. While useful as a hack, when the program (friend network) is small, global variable ("global" posts) seriously screw things up, as the program begins to scale.

If you post something, or declare a global variable, everyone and everything can see it. When you have 20 friends, or a 20-line program, this is not much of a problem. You can use your sense of smell to detect problems, and fix them as needed.

But these beasts, they live on forever. They cause unforeseen errors and gaffes.

In the programming world, the solution is encapsulation; defining variables within a context or a subroutine. These variables are invisible to the rest of the program. They arise as soon as control flows in, and die as control flows out.

For large software projects, this is not just a good idea, but a necessary idea. You shouldn't have to worry about the entire universe getting screwed up, just because you changed the name of a variable.

To be fair, Google+ and Facebook do allow you to customize and limit the scope of pictures and comments you post. That is, encapsulation is possible. But it is cumbersome, and I don't know many people who use it skillfully. Programming is work; posting on Facebook is supposed to be fun.

This probably explains the rising popularity of messaging apps (iMessage, WhatsApp, Snapchat) where group identity is a fundamental building block. Groups automatically provide localized contexts. The proportion of original content that people feel comfortable posting on messaging apps is so much higher.

Thursday, November 12, 2015

A Moral Argument for Eating Meat

I promised that I would stop eating meat, the year I turned 35.

I failed.

The main arguments for going vegetarian are convincing:
  • the greenest thing that an average person could do; nothing else comes close
  • the cruelty and inhumanity of factory farming
  • something screwed up about raising sentient life for food
I've scoured for arguments that counter the last point. Even if there was a carbon-neutral, perfectly humane way to raise animals, and slaughter them painlessly, would we be justified in raising and killing animals?

So far, none of the arguments seem compelling. The only narrow exception is when the survival of the individual is at stake.

For now, the story I tell to rationalize my choices is that most of my meals are vegetarian. One can't let the perfect be the enemy of the good.

Abstinence is hard, so moderation will have to do.

In a hundred years, our great-great-grandkids might look at our food choices with disgust. They might view us with the same odd combination of outrage and pity that with which we view historical moral crimes (slavery?).