# Gravity Example: 0.04s of Computation

Recently, we posted about a way to redefine gravity in terms of a joint model that can be used to quantify defensive interaction, offensive spacing, and spatio-temporal motion of a possession. The result yields a sparse N x 2P x Q x R x S x Z tensor that characterizes the interactions of players, locations on the court, time within possession, and resulting score. The entries of the tensor are either zero (if the entry of the tensor is not observed) or are the estimated gravity values observed. In this article, we take a very particular time slice and extract estimated gravity values.

## Equilibrium: For Better, For Worse

One key assumption is that every defensive setting in in equilibrium. What this means is that for a given offense, the defense is in the best position it can be in, physically. It may be an entirely wrong defensive set, communication poor, and their coach may lose his mind in the process; but it’s the defensive position the team takes. For better, for worse.

Similarly, the offense is viewed to be in equilibrium as well. This means that the offense is getting to the spacing that they are capable of given the circumstances of the possession. For better, for worse.

We make this assumption in an effort to extract out the gravity values. Under equilibrium, we are able to obtain a series of equations that yield masses for players that describe the gravitational pull of a player. The larger the mass, the more gravity that player draws across all players.

Once we have this assumption in hand, we can start to pick away at the interactions on the court.

## Basic Example: One Snapshot in Time

Let’s start with a 0.04 segment of time. In this case, a team steps into its initial set in the half-court and the defense is in position. In this case, we note that the red team is on offense while the blue team is on defense. We landmark 12 locations on the court: 10 players, the basketball, and the basket. ### Partial Bodies

In the most basic example, we can begin to dissect portion of the court into partial bodies. In doing this, we obtain simple rigid body equations that help us break down the mathematics associated with the possession. For each defender, the basic building block combination is the primary offensive player, the basketball, and the basket. This was the simple Man-You-Ball and Between-Your-Defender-And-The-Basket philosophies. Extraction of a Partial Body from the Possession. Pardon the flipping. That’s an artifact of imshow versus plot commands.

Using the partial body, we make a second assumption: the basketball has constant mass. What this means is that the basketball serves as a reference point. By making this assumption, we are able to compare masses across possessions. Under this conscious choice, as opposed to the basket, we are able to see how the basket gains larges amounts of gravity on drives to the basket; as a driving ball-handler will always have the basketball in hand. It can be argued to make the basket constant mass; and that’s fine. But that’s not the choice here. Either way, without a suitable reference point, solution of the system is not attainable. As you’ll see in a moment.

### Reference Frame

Once we extract out the partial body, we must focus on building a reference frame to perform the mathematics. As we opted to make the basketball the constant mass quantity in our system, we can build our reference frame.

A reference frame is the coordinate system for which we can perform math. Selecting a smart reference frame makes the mathematics easy. In this case, using constant mass for the basketball, we can make the negative y-axis serve as our reference direction. What this requires is a rotation matrix. We replaced the Rockets’ court with a Rotated Partial Bodies problem! Hooray math!

Now we see that the basketball is the y-axis. And since we are at equilibrium (assumption one) with the basketball having mass one (assumption two), we can solve the remainder of this partial bodies problem!

### Solving Partial Bodies

To solve the partial bodies problem we apply the equilibrium state and break up the vertical motion from the horizontal motion. Equilibrium merely suggests that the state is not accelerating in any direction. Therefore, the forces in the vertical direction sum to zero and the forces in the horizontal direction sum to zero. Before we begin, let’s drop down the reference axes and draw in the angles we will need very shortly. We have included the angles. The defender is the origin of the reference frame.

For horizontal motion, we see that the offensive player is to the right (positive direction) while the basket is to the left (negative direction). For completeness, the basketball is neither right nor left, indicating no horizontal influence on the system. This is why we rotated the system.

The black line from the defender to the basket identifies the force between the defender and the basket. Call this F_basket. The red line from the defender to the offensive player identifies the force between the defender and the offensive player. Call this F_player. Finding the angle each of these two lines with the x-axis, and we are able to quantify the right and left motion of the two bodies.

Using equilibrium, we obtain 0 = F_player * cos(A1) – F_basket * cos(A2). Since we are modeling the player interaction as gravity, we can write the forces as gravitational pulls. In this case, we get F_player = m_defender * m_player / d_{def,play}^2. Here, m_player is the mass of the offensive player; m_defender is the mass of the defender; and d_{def,play} is the distance between the defender and player.

As we have equilibrium, the mass of the defender cancels out of both terms and we are left with one equation and two unknowns.

For vertical displacement, we again apply equilibrium to obtain our equation. In this case, we assumed the mass of the basketball is one. This allows us to write equilibrium as 0 = F_player * sin(A1) – F_basket * sin(A2) – F_basketball. The forces are the same as in the horizontal case. Except this time, F_basketball enters into the equation as m_defender * m_basketball / d_{def, ball}^2. Again, the mass of the defender cancels out. And from our assumption, m_basketball = 1. This is a constant. And we obtain the second equation with the same two unknowns.

In this case, we are able to solve for the partial body by Gaussian elimination!

## Expanding to the Entire Possession

Expanding on the entire possession, if we simply look at the partial body problem in repeated fashion, we will not obtain full rank to extract out the eleven masses we require! Similarly, the partial body solutions are only in vacuums; meaning that introducing another player will change the equilibrium. In this case, we must look at the full body solution. In this case, for each defender this yields two equations and 10 unknowns! Not a good situation.

To regulate this, we apply a jackknife technique. The jackknife is a process that eliminates a data point from the system and computes the system without the data point. In fact, this is exactly the process we performed in the partial body system above!

This time, we must use multiple jackknife points. In this case, we only set the basketball as the reference point. Therefore we shall apply 11 jackknife iterations to obtain the entire system.

So let’s apply that to our single snapshot!

Apologies for swapping the colors of offensive and defensive players. However, as this movie plays out, we map each player on the court to the basketball. We then construct the reference frame, and then sniff out the rotation matrix. From here, we identify the horizontal and vertical components of each of the eleven jackknifed bodies. And we pause for a moment to realize that statement sounds more morbid that it should.

The resulting jackknife process yields a system of twenty-four equations and eleven unknowns. More importantly, this system of equations has full rank!!! This is important as we need to solve the homogeneous system we built. The only challenge now is that we have a nonlinear homogeneous system.

Note that homogeneous means that the sum is zero for all equations in the system. The nonlinearity comes from the N-Body problem we have constructed using the gravitational forces used above. In the above examples, we could easily solve the equation. In this case, we no longer have that luxury.

## What Are We Extracting?

With the mechanics above, we can take a quick moment to look at the network we have just built. The homogeneous system, in all its glory.

Here, the green network are the constant gravity values being obtained from the basketball. Recall that here, the basketball has mass one. The cyan network is the gravity associated with the basket. This is a residual effect from the partial bodies problems. Similarly, the black network is the offense-defense interaction network. This portion is also distilled from the partial body solutions. The red network and blue network come from the interaction within each respective team. This is the skewing that will exist due to the team interaction that the partial body solutions cannot capture.

While the network drawn is a pretty picture, we have to realize all the math performed is on the rotation spaces in the video above. This means the lines are all weighted as gravitational forces with sine and cosine adjustments due to the reference frames.

The solution to this system is not so straightforward. Newton’s method does not work as the system is not square; in fact gradient methods suffer greatly and will explode. Nelder-Mead can help but converges rather slowly; thanks to the 11-dimensional search space. In this case, we rely on Powell’s Method for identifying a root solver.

Hint: We can turn this root finding problem into a convex optimization problem by merely taking a square of the equilibrium functions.

For this time snapshot, we obtain the masses (gravity values) as ## Interpreting Gravity Output

Looking at the output above, the first five gravity values are for the offensive players. The second five gravity values are the defensive players. The last gravity value is the basket.  Let’s look at the play again. What this tells us is that on offense, we find that Player 3 and Player 5 has the highest gravity in the system. Player 3 is the elbow player on offense. We actually see the defender of the ball handler and the defender on the right wing (Player 2) are sagging ferociously off their men towards the basket and towards Player 3. Similarly, we find that Player 5 is being guarded a little tighter than most other players.

We also see the basket obtain a substantial amount of gravity in this time snapshot. Looking at the play above, this is rather obvious as almost every defender is sagging closer towards the hoop than necessary. The ball-handler defender is more than seven back off his man. The defender of Player 3 is a few feet back, saddled in the lane. The defender of Player 2 (right wing) is the worst offender, almost playing in “No Man’s Land” as if to pre-double-team Player 3. Player 4’s defender is also straying, but not as bad towards the basket.

## What Next?

As we have shown how to extract out the gravity values (masses) of each player in the time snapshot, we populate the tensor slice that occupies the possession. We will see a sparse effect as this time snapshot only covers 0.04 seconds. Suppose this possession lasts 15 seconds, then we expect 374 other snapshots. And since there are roughly 950 players (475 offense, 475 defense), we expect to only populate 10 positions.

By incorporating the result of the possession, we can begin to classify the possession as effective or ineffective when it comes to defense or spacing, depending on the goal in mind. In doing this, we will require some form of generalized Singular Value Decomposition (SVD) such as the CP-Decomposition or the Tucker Decomposition. (CP is preferred)

However, those steps get really messy; and you know… begins to build the actual edge.

Happy Holidays!

1. Abhi says: