The Art of Sketching: Trajectory Analysis

In a recent 2017 paper posted by Andrew Miller (Harvard University / Philadelphia 76ers) and Luke Bornn (Simon Fraser University / Sacramento Kings) titled “Possession Sketches: Mapping NBA Strategies,” the duo takes a well-known manifold learning technique called trajectory analysis and develops a methodology of classifying NBA actions through the use of functional mapping of segmented trajectories, called sketches, to build a vocabulary and application Latent Dirichlet Allocation (LDA). This area has become popular over the years due to applications such as Luis Oliviera’s trajectory-based segmentation-classification of handwritten digits (2000) and Buchin, Kruckenberg, and Kolzsch’s migration analysis (2013). The technique of sketching, while in the same family of research, is still quite the novel idea and faces many of the same challenges to being statistically significant (identify proper signal among the spatio-temporal noise) when it comes to classification.

In this article, we mildly walk through the process of sketching to identify why it’s a fairly neat idea, where some of the pitfalls are, and how it can be applied. In this post, unfortunately, there will be no direct code for three reasons. First, the fun examples come from data that is not releasable to the public and therefore releasing the code to process the data will give insight to the updated technology and data structure of Second Spectrum data. Second, my reconstruction of the code would poorly represent the actual work performed by both Miller and Bornn. While I am indeed capable of reconstructing the code; being the nuanced statistician as I am, I will take extra liberties as I see fit that may not align with the vision of the authors. Third, I am unable to go into details that are not purely released to the public through Miller and Bornn’s work, as I have an NDA in place (not connected to either Miller or Bornn) about discussing this particular topic in detail.

So why go into detail about sketching? Because it’s cool. And my personal background in differential geometry and spatio-temporal statistics urges me to identify to anyone interested in advanced statistical analysis in NBA data about this type of research.

In this article, we will break down the three components of Sketching: segmentation, templating, and modeling. Heavy focus will be given to the first of the three elements. Discussion will be given to the second and third of the three elements.

Trajectory Building

The goal of sketching is to take player tracks from motion data and develop a template that statistically identifies offensive motion in an NBA offense. To begin, we focus on the player tracks. A player track is a trajectory. That is the path an object takes over a desired period of time. We can represent a trajectory as the set of points x_1, …, x_t, for t consecutive time steps. Let’s take a look at a particular play.

Golden State Warriors: Sideline Wing Twist + Elbow Pin Down

The illustrative play we look at comes from the Golden State Warriors. In this illustration, we are concerned with two components: the Sideline Wing Twist and the Elbow Pin Down. The Warriors will occasionally use the Wing Twist with Steph Curry and Klay Thompson in an effort to tangle defenders and either open a lane towards the basket or break for the three point line. A secondary elbow pin down screen typically comes from the top of the key; either a Zaza Pachulia or JaVale McGee to pick up a wing scorer. The pin down will either free up a jump shot at the perimeter, or a drag-action screen into the lane. By combining these two actions, we can identify four different types of actions; dependent on the response of the defense.


The combination of actions making a Sideline Wing Twist and an Elbow Pin Down. Klay Thompson (black), Stephen Curry (blue), and JaVale McGee (green) work through the three synchronized step to put these two actions together. McGee makes a fourth action as a drag read into the open lane yielded by the defense.

In the diagram, we see the wing twist action. Stephen Curry (blue) feigns popping to the perimeter and doubles back to Klay Thompson (black) for a screen. Instead of screening, Thompson and Curry weave. As they weave, McGee steps in to show a potential elevator doors action to spring Thompson to the lane.

After Thompson breaks for the lane, Curry doubles back towards McGee, who takes the extra step to pin down Curry’s defender at the elbow for a perimeter look. After the pin down, McGee finds a completely open lane as Thompson receives the ball in the lane. The fourth action finds McGee nearly uncontested at the rim for two points.

From the illustration, we see that the collection of blue segments is the trajectory of Steph Curry’s offensive possession. Similarly, the collection of black segments is the trajectory of Klay Thompson’s offensive possession.

In Motion: Animating Location Data

We can first start by animating the location data. In this process, we can extract out the points of interest, building a simple matrix of entries that contains player, team, x-location, y-location, time. By leveraging the matplotlib.animation package, we can build an animation updater than simply reads scatterplots conditioned on time. Including some other basic analytics, we can build a player movement animation.

In the animation, we see the twist action at the bottom right of the court. After the exchange, we see Curry double back and take on a pin down from McGee. As Thompson was double teamed and Curry’s defender tracked Curry to the perimeter, McGee was able to read the open spot on the court and break for an eventual lay-up.

Incorporating Trajectories

Once we are able to visualize the play, the next step is to identify the trajectories of each player. A simple way to represent this is to plot the movement as a static plot. In doing this, unfortunately, we will get a gigantic mess on the court. Instead, we opt to animate this process while holding the offensive possession trajectories in memory.

I lovingly call this a Snail Plot. This is due to the trajectories being mapped out as the player moves around on the court. After enough motion, there will be an indistinguishable noodle soup. However, as the tracks play out, we can start to see each player’s motion in relation to every other player on the court.

Let’s Isolate JaVale McGee

Let’s take a look at JaVale McGee’s trajectory. In this case, McGee collects a made basket on defense and passes the ball in to Curry. He then heads down court, lingering at the top of the key, waiting for the play to develop and make his move. After the twist action occurs, McGee sets a quick screen and breaks for the basket.

We now have an isolated trajectory for McGee. How do we understand his spatio-temporal role within this offense?


The first step in the sketching process is to break apart segments of an offensive play. Recall, there are two primary actions that make up this Warriors’ play. The method used by Miller and Bornn is to use low-velocity movements. A low velocity movement is defined as approximately .25 seconds of less than 0.1 feet per second movement. In this case, seeing as we have JaVale McGee’s trajectory, we should take a look at his speed on the court.

We immediately see all the segments of McGee’s trajectory that breaks apart due to sustained low velocity movements. If we look at the half-court possession only we see that there are actually three segments to McGee’s motion. Each value on the x-axis represents a mere 0.04 seconds; which indicates that .25 seconds is six contiguous time steps.

In this vein, the half court action starts at time step 200; this is eight seconds into the possession. From there, we see McGee remain relatively stationary; which is his presence at the perimeter.

The first burst of motion is the elevator door action with Curry during the weave, to let Thompson slip into the lane, drawing McGee’s defender. This is the large spike on the quick movement to knock Allan Crabbe to the back of Thompson; forcing Maurice Harkless to chase Thompson.

After the screen, there is a small burst which indicates McGee’s flow into the elbow pin down. The brief moment after the screen, McGee actually goes beneath 0.1 feet per second for nine time steps; forcing a cut point and leading him into the backdoor cut after reading the defense.

We then see the acceleration to the basket, the quick step out to the short corner, and then the burst for the basket on the Thompson miss and put-back. Note: Thompson was blocked. McGee picked up the missed attempt and made the uncontested lay-up.

What we have now, mathematically, are three segments of the sketch for JaVale McGee. Each segment has its own length. The first segment is approximately 25 points. The second segment is approximately 130 time steps. The third segment is approximately 120 time steps.

Functional Data Clustering

The second step of Miller and Bornn’s sketching methodology is construction of the action template, which is the hardest part of the sketching process. Here, their goal is to develop a bag-of-words approach to use LDA to identify topics associated with offensive mechanics. To build topics, we must have a mechanism for defining words; or a vocabulary.

Their methodology starts with a clustering technique by computing a sequence of 250 Bezier curves that serve as cluster centers for each of the potential clusters of segments of trajectories.

Bezier Curves

A Bezier curve is a piecewise curve constructed in a similar vein as splines or localized polynomials. The attractive properties for Bezier curves are the resulting curve rests within its own convex hull and they can be defined in a recurse, efficient, manner. Due to these two primary properties, Bezier curves are commonly found in animations; or movements in the computer graphics world. Note: Tackling a discussion on Bezier curves here will add another 1,000 words (as this was a two-course lecture when I learned about these in graduate school). Feel free to dive in on Wikipedia. It’s actually not too bad on development; but light on detail.

However, finding these Bezier curves helps transform the segment data into a vocabulary, where the index of the Bezier curve serves as the word of the segment. This pretty slick idea allows us to now place a discrete distribution on the bag of words through the use of LDA!

It should be noted, that the clustering algorithm here must have high amounts of repetition in order to gain enough signal to cluster. As noted in Miller and Bornn’s paper, they leveraged 190,000+ possessions. Given this, they have less than 75% of a season. Of that, a majority of players may only have a couple actions that classify properly. Due to this, an assumption of exchangability on player motion (Curry is the same as Thompson) may be sitting within this process.


The final part of the model is the use of Latent Dirichlet Allocation. This process is a well known model introduced in 2003 by David Blei, Andrew Ng, and Michael Jordan. This is a known as a topic model framework that attempts to identify words to topics gleaned from documents. A common example is the use of words such as “tumor” and “benign” that map to the topic “cancer.” The goal of topic modeling is to identify a suite of topics from each document and identify a probabilistic distribution of words associated to the topics.

Here, we assume that documents are offensive possessions, topics are the strategies, and the Bezier curve segments are words. Therefore, the goal is to extract out strategies and identify the associated curve segments to join them.

Further Analysis

Given the topic modeling that can occur, Miller and Bornn took another step in understanding pairs of words within a strategy. This is, how two actions compare between two players within a strategy. This analysis would help shed light into interactions such as Hammer screens with a PnR strong side and a back screen on the weak side. Similarly, this can look into a Warriors twist with an ensuing elbow pin down. I encourage you to head back to the top of this post and download the paper to read.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.