## HackMIT: Polyglass

I attended HackMIT 2013 and had an absolute blast! Kartik Talwar, Spencer Hewett and I make a fantastic team.

In the turmoil that followed the hackathon (taking a weekend off of schoolwork and research has consequences), it slipped my mind to post our project!

We created Polyglass. A Google Glass application that analyzes the video in slow motion using the Eulerian magnification algorithm to calculate the human pulse from a video frame in quasi real-time. Using video alone, we achieve the same functionality as a polygraph.

The picture below is a demo of our project; it compares the original video frame to the frame processed by Eulerian Magnification. This processing is an implementation of the Eulerian Magnification framework published by MIT.

Portions of our source are on Kartik’s github.

## Braille Cell with VPython

The internet went down at my house, and I decided to play with vpython again!

#type individual brl cell using numkeys
from visual import sphere
R = 0.2 #filled dot radius
r = 0.1 #empty dot radius

#corresponds to numkeys
dotdict = {
'7': [1,3], #dot 1
'4': [1,2], #dot 2
'1': [1,1], #dot 3
'8': [2,3], #dot 4
'5': [2,2], #dot 5
'2': [2,1] #dot 6
}

fulldot = dotdict.keys()

def draw(dots):
[sphere(pos=dotdict[dot], radius=r) for dot in fulldot] #create empty dot matrix to represent empty cell
[sphere(pos=dotdict[dot], radius=R) for dot in dots] #fill appropriate dots

string = raw_input()
if string.isdigit(): draw(str(string))


Let’s see it in action! The letter “j” (or “just” in G2):

## Simple Cubic Lattice

Today, let’s have some fun playing with perspective rendering in Python! My graphics package of choice is VPython:

<code>sudo apt-get install python-visual</code>

Suppose we want to represent a simple cubic lattice: Using the visual package, we can create a collection of spheres at positions $(i,j,k)$ with $i,j,k = -L…L$.

from visual import sphere
L = 5
R = 0.3
for i in range(-L,L+1):
for j in range(-L,L+1):
for k in range(-L,L+1):
sphere(pos=[i,j,k],radius=R)

Resulting in this beautiful rendering:

But what if we want to change the color? Simply alter the last line:

<code>sphere(pos=[i,j,k],radius=R).color = color.blue</code>

Less atoms? Alter the value of L.

 L = 1

Same number of atoms with smaller radii? Alter the value of R.

 R = 0.2

Want more advanced computational physics with Python?

## Do You Even Search, Bro?

I recently came across a software engineer I respect greatly who is unfamiliar with the basics of grep (I know, right? Blew my mind). This is for him, hopefully it will help others. If you’re already familiar with this black magic || want to see a cool implementation, check out Grep is a Magical Beast.

Grep’s syntax is fairly simple

grep [options] search_string file|dir

Grep supports regex as the search_string; whip it out if you’re versed in its beauty.
If you’re using a multiword search_string, you must wrap the string in single quotes.
Search all directories by listing *. as dir.
Search subdirectories by restricting the path and adding an -r flag:

 grep -r 'Carl' ~/Dropbox/LlamasHats/*

The [extremely] basic flags are:

Searching for ___? The flag for you
Text in subfolders -r
Whole words only -w
Case-insensitive text -i
File names only -l
Number of occurrences only -c

Is your mind blown yet? No? Check out ack. The abundance of CL switches will blow your mind. The syntax of ack is the same as that of grep. Their documentation is great.

The main difference I’ve found between grep and ack is speed. Here is a great post by Perl Monks on reasons to switch.

Using find is great for filename searches. find‘s syntax is a bit different than grep’s

find file|dir [options] search_string

A generic search:

find . -iname '*.sty'

## What Does This Wobbly “d” Do?

What is the difference between $\frac{d}{dx}$ and $\frac{\partial}{\partial x}$?

…is a question I get surprisingly often when tutoring friends.

Short version: The difference is all about dependency!

The “regular d” in $\frac{d}{d x}$ denotes ordinary differentiation: assumes all variables are dependent on $x$ ($\rightarrow$ envoke chain/product rule to treat the other variables as functions of $x$).

The “wobbly d” in $\frac{\partial}{\partial x}$ denotes \partial differentiation and assumes that all variables are independent of $x$.

You can make a straight d from a wobbly d by using a beautiful thing:

$\frac{df}{dx} = \frac{\partial f}{\partial x} + \frac{\partial f}{\partial y}\frac{dy}{dx} + \frac{\partial f}{\partial z}\frac{dz}{dx}$

You can remember it this way: the \partial derivative is \partially a “d”, or the the “wobbly d” is \partial to nemself and bends nir neck down to look at nirs reflection $\partial$.

Sidenote: Ne/nem/nir/nirs/nemself is a pretty swell gender neutral pronoun set!

Longer version: Before we start – what is a derivative, anyway?

The derivative of a function at a chosen point describes the linear approximation of the function near that input value. Recall the trusty formula: $\Delta y = m\Delta x$, where m is the slope and $\Delta$ represents the change in the variable?  For a (real-valued) function of a (real) single variable, the derivative at that point is = tangent line to the graph at that point.

The beauty of math is: $m = \frac{\Delta y}{\Delta x} equiv$ “How much one quantity (the function) is changing in response to changes in another quantity ($x$) at that point (it’s input, assuming $y(x)$).”

So, it makes sense that derivative of any constant is 0, since a constant (by definition) is constant $\rightarrow$ unchanging!

$\frac{d(c)}{dx}=0$, where $c$ is any constant.

What about everything that isn’t a constant?

That means, $\frac{d(x^2)}{dx} = 2x$, since $x^2$ is dependent on $x$. $\frac{d}{dx}$ denotes ordinary differentiation, i.e. all variables are dependent on the given variable (in this case, $x$).

But what about $\frac{d(y)}{dx}$? Looking at this equation, we immediately assume $y$ is a function of $x$. Otherwise, it makes no sense. $\frac{d(y)}{dx} equiv \frac{d(y(x))}{dx}$

On the other hand, $\frac{\partial (y)}{\partial x}$ denotes \partial differentiation. In this case, all variables are assumed to be independent.

$\frac{\partial (y)}{\partial x} = 0$

Let’s compare them with an example. $f(x,y) = ln(x)sec(y) + y$

$\frac{\partial f}{\partial x} = \frac{sec(y)}{x}$

$\frac{df}{dx}$ implies that $y$ is dependent(a function of) $x$, i.e. $f = (ln(x)sec(y(x)) + y(x))$

$\frac{df}{dx} = \frac{dy}{dx}(ln(x)tan(y(x))sec(y(x)) + 1) + \frac{sec(y(x))}{x}$

As you can see, $\frac{\partial f}{\partial x} \neq \frac{df}{dx}$.

By the way, to use LaTex in Blogger include the following before </head> in your Template (source):

<script type="text/x-mathjax-config"> MathJax.Hub.Config({tex2jax: {inlineMath: [[&#39;$&#39;,&#39;$&#39;], [&#39;$&#39;,&#39;$&#39;]]}}); </script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"> </script>