They're watching your every move

There are lots of fun ways to play with your phone: Angry Birds, Snapchat, Facebook, Face-swapping. Maybe you like to play with sensors? Anyone? Anyone? Well, in this post I will share some Python code and a video of how you can stream your Android's accelerometer data to your laptop and then visualize it. In fact, you can do this with any of the sensors in the unit, the accelerometer, gyroscope or the magnetometer. read more

How Calculus III can help us identify Ambiturners.

Derek Zoolander famously was not an ambiturner. He had to go through a hero's journey to be able to turn both left and right. In this post we will take a hero's journey to identify right and left turns from running data using only GPS measurements.

In my last post I described an algorithm to reduce the number of points on a 2D curve that preserves the basic network structure of the curve. This algorithm, the Ramer-Douglas-Peucker (RDP) algorithm helps us to identify abrupt changes in a curve, where abrupt is subjective and up to the user to decide upon.

In this post I present a novel and simple approach to answering the following question: Did I take a left or right turn and how did I take that turn? Smoothly? Roughly? Constantly? The method presented here is new and remarkably simple compared to other methods in the literature. Most methods I saw relied on accelerometer data which needed heavy machinery such as Kalman filters to make similar determinations.

Calculus III to the rescue

The basic vector description of the plane and 3D space always seems like a bore when teaching. It's hard to get students to be fired up about vector addition and the algebraic structure of euclidean space. So finally, here is an interesting application of the dot product and cross product that goes beyond the ubiquitous force equations from physics.

Consider the map below. Let's assume we have identified the turning points from the RDP algorithm as described in my previous post. IL_three_points_cIdentifying whether it is a right or left turn is extraordinarily simple. Given any three points on a plane we can find the angle that subtends the middle point with our friend the dot product,

 \vec a \cdot \vec b = ||\vec a|| ||\vec b|| \cos\theta

On the map above we will have something like this,IL_three_points_c_angles

If the angle is between 0 and 180^o it is a right turn and if it is between -180^o and 0^o it is a left turn. But to solve for the angle we have to use the \cos^{-1} function which only has values in a range for a range of 180^o. This is where the vector cross product saves the day. The 2D cross product is simply the determinant. If the determinant is negative, the angle is between 0 and 180, if the determinant is positive it is between -180 and 0. Thus, left turns and right turns.

Finally, our algorithm is the following:

  1. Apply the RDP to the dataset of lat/lon's. This leaves us with a network G of vertices and n-1 edges.
  2. For i in range(1,n-1) form vectors for the i-1, i, and i+1 vector (as shown above) and compute \theta.
  3. Calculate the determinant and determine left turn or right turn.

That's it!!!!! Glorious, glorious Calc III. Here is a map of run I took in Gedera and the results of the algorithm applied. The run starts with the left-most point. This algorithm resulted in 100% accuracy.gedera_run_c

Type of turn, angle Right turn, 36.9872677438 Left turn, -27.8188864289 Right turn, 55.4872049488 Left turn, -114.980809001 Right turn, 148.508392832 Right turn, 113.14225291 Right turn, 163.80922161 Left turn, -150.035986035 Right turn, 175.043761198 Right turn, 161.791261833 Right turn, 83.6023186647 Right turn, 109.851066119 Left turn, -126.533104243 Right turn, 116.820422235 Left turn, -97.4253631752 Right turn, 160.584337619 Right turn, 93.0049662148 Left turn, -164.456048578 Right turn, 139.971999906 Left turn, -142.289251078 Left turn, -165.463072689 Left turn, -143.612951911 Right turn, 119.067520889 Left turn, -155.864187354 read more

Memory vs. Experience: Behavioral economics explains why the (back) end matters

"I can't leave until I make a shot." You'll hear this all the time on a basketball court. Growing up I had a friend that was annoyingly loyal to this behavior. Why? Sure, we all want to make another shot, but is there a more profound reason? The research of Daniel Kahneman gives a possible explanation: The Peak-End rule.

Kahneman is a Nobel-prize winning psychologist famous for being one of the founders of behavioral economics, and, in one of my favorite books, Thinking Fast and Slow, espousing a view of human behavior antithetical to many previously held notions. read more

Teaching Gifted & Talented Students in Hong Kong

This past month I taught a course, "Paradoxes & Infinities," in Hong Kong through the Center for Talented Youth, a gifted & talented program through Johns Hopkins University.

DSCN4291My lasting impression, a few days after completion, is that there still are some great ways to teach advanced math to advanced students. The organization and the logistics of the program itself had some some issues; but these were not negative enough to mollify my experience.

The course is an intensive three week program. The curriculum is math and logic based with paradoxes as the connective tissue. In order to discuss many paradoxes one needs to have a basic understanding of set theory (Russell's paradox), probability (Monty Hall paradox) and sequences (Achilles & the Tortoise) with some other topics sprinkled in. We also studied cardinality, symbolic logic, game theory, combinatorial games and the structure of the real numbers. Each day I, or my TA Raymond, would present brain teasers and puzzles. The combination of all these topics and activities lead to lots of fun but was, at times, a bit overwhelming. read more

Is Israel Safe?

When I decided to move to Israel the most frequent question, asked overtly or discretely, was "Is it safe?" The undertone was always that Israel is not and I may be a bit crazy for going. This post will examine how safe Israel is using the USA as the default comparison. There are so many ways to measure safety. Feeling safe is much different than actually being safe. What it means to be safe is not clear. However, there are some basic metrics we will explore here.

The first thing that comes to mind is homicide. The following graph comes from the world bank. The USA is, at all times, at least twice as dangerous than Israel for homicides.  read more

A Visit to a High School Calculus Class

It's funny what high school students notice. I paid a visit to a high school calculus class and gave two lectures about applied math. Both lectures were variants of a typical themes; what is mathematics and how is it used in today's society. The talk was very visual and used two mathematical ideas, network theory and optimization, to motivate the study and beauty of mathematics.

I began the talk by asking them to consider the following picture from a children's book. elephant_waterI borrowed this from a talk given by Timothy Gowers on "The Importance of Mathematics." The students very quickly realize the water spouting from the lazy elephant is not obeying Newton's law of gravity. From here I go into a short bit on mathematical modeling. I ask them what they know about bacteria and I receive a typical answer; bacteria grows exponentially. We look at the graph and they realize, through a verbal discussion, that \displaystyle{\lim_{\rightarrow \infty}}e^x = \infty. From here the students understand the exponential growth model needs to be refined. We end with the graph of the logistic equation. read more