Sunday, September 23, 2018

Softball Optimization Revisited

About a year ago, I wrote about using a computer program to optimize softball lineups by putting players in their preferred fielding positions, to the greatest extent possible. In this post I'll discuss how my philosophy as team captain has evolved since then, and how I've matured my optimization program to match.

the team after the spring 2018 championship, a narrow loss
back row, left to right: Shayna, Evan, Daniel, Paul, Mike, Brett, Peter, Josh
front row, left to right: Buddy, Hannah, Emily, Kayla

My Philosophy on Ideal Lineups

What is the ideal strategy when making lineups? Two approaches I've tried are to maximize team strength, and to maximize player satisfaction. I've found that both approaches have issues if taken to the extreme: maximizing team strength marginalizes weaker players, and maximizing player satisfaction decreases overall team strength, e.g. if certain players are allowed to monopolize their few preferred positions.

Rather than optimizing solely for team strength or player satisfaction, I now believe the ideal strategy is to maximize team morale by simultaneously optimizing and balancing:
  1. satisfaction: players' satisfaction with their assignments
  2. strength: the team's probability of winning games
Why do I think morale is the right unifying value to be maximized? In short, because I think that's what people seek in sports teams, especially at the rec level. I also believe that explicitly trying to win at all costs often has the opposite effect, by burning players out, creating rifts, and generally causing disengagement. I think the best way to maximize team strength is to arrive at it by creating the right atmosphere, and that ultimately comes from morale. This sort of environment also fosters camaraderie and keeps people happy, a obviously desirable outcome that also further improves team performance.

So ideally, every player is assigned to a position they like, they perform well, and the team wins. This leads to individual and team satisfaction, and ultimately to positive morale. But how to optimize for this?

Quantifying Team Strength

Quantifying team strength requires additional information beyond where people like to play. It requires a more fundamental breakdown of which skills underpin the various positions, how the positions compare at skill requirements, and how individual players compare at these skills. It also requires knowledge of the strategic importance of the various positions, which are significantly uneven.

In our league, with the fast pace of the game and relatively low level of seriousness, it's far too cumbersome to maintain player stats, so I had to rule out an absolute assessment of skill such as fielding percentage of batting average. Instead, I settled on relative assessments. I may not know Player A's top throw speed, but I can venture with some confidence if it's higher or lower than Player B's. Similarly, I may not know how much throw strength is required to play shortstop, but I know it's higher than second base.

Bringing this together, I brainstormed seven fairly independent skills that I think underpin the various positions, in varying amounts. I then ranked every player by their aptitude for these skills, and every position by its requirements for these skills.

player and position rankings; pseudonyms used for anonymity

There's a good deal of subjectivity here, as the rankings rely on my informal and unscientific judgement, and it's also significantly subject to confirmation bias. On the other hand, this approach is simple, lightweight, and easy to maintain - in my opinion, the right fit for a rec league. But what about the strategic importance of each position? For example, it's clearly more valuable to have a strong pitcher than a strong catcher, since the pitcher has a much greater effect on the game outcome.

Weighting for Strategic Importance

For this, I use defensive outs generated by each position as a metric for strategic importance. I estimated that 2/3rds of our outs are unassisted, e.g. fly outs or line outs, and 1/3rd of our outs involved two positions, e.g. groundouts. Then, I estimated how many outs each position generates in a typical game, noting that the result should sum to ((2/3)*1 + (1/3)*2 players per out)*(3 outs per inning)*(6 innings per game) = 24 player-outs per game. I estimated these weights based on my league experience:

outs by position per game, estimated

Scoring a Lineup For Strength

My lineup generator reads the rankings shown above, and converts them to a matrix, where the strongest player for each skill is given a 1.0, and the weakest a 0.0, and so on with the positions. Linear interpolation is used for the players and positions between the extremes. Then, evaluating the strength of a lineup is fairly straightforward:
  1. Initialize team strength = 0
  2. Pick the first player on the field
  3. Take the dot product of the player's skill with the requirements for this position
  4. Multiply by the weight for this position
  5. Add this number to the team strength
  6. Repeat Steps 3-5 for all remaining players

Down-Selecting to a Single Lineup

From my prior work, I have a method of quantifying player satisfaction with assignments, based on survey results asking players to classify each position as "like", "neutral", or "dislike". From this, I generate a "satisfaction" score, 0-100%. For example, 93% might represent nine players liking their assignments, and one player disliking their assignment.

I believe that in the regular season, ideally, all players should sit the bench an equal amount. To this end, I have also incorporated manual constraints that allow me to constrain players to arbitrary positions and optimize the remaining positions.

What is the upper bound on team strength? The numbers used are dimensionless, so to approximate an upper bound, I temporarily discard all positional constraints and survey data, and seek only to optimize the strength score. I then take the best result as the upper bound, and use it to normalize subsequent lineup strength scores, also 0-100%.

Incorporating player preferences reduces team strength slightly by reducing the solution space, so there's a trade-off to be made. I think the sweet spot is enforcing a minimum satisfaction of around 90-95%, and then optimizing strength given this lower bound. Typically the survey has a fairly minor penalty on team strength of around 5-10%. This is due to players generally liking positions where they are strong, and disliking positions where they are weak. Constraints can have a more significant impact on strength, particularly when the benched player is relatively strong, by as much as 10-20%.

Generating a Sample Lineup

As an example, I'll show the process of generating a lineup using the sample rankings shown above. Suppose that Oscar and Alan have not sat the bench yet, Earl has asked to play second base due to a mild injury, and Marvin will be absent.


Constraints = {
                 'Earl', 'Benched'
                 'Alan', 'Second base'

players_absent = {


Suppose I also set:

satisfaction_minimum  = 0.90; % 0-1

After evaluating about 1,500 random lineups per second for a few seconds, the optimized result is returned:

Satisfaction: 93%
Strength: 95%

Pitcher: Andrew
Catcher: Ryan
First base: Samuel
Second base: Earl
Shortstop: Igor
Third base: Isaac
Left field: Aaron
Left-center field: Vlad
Right-center field: Eddie
Right field: Ulrich


Note that the constraints were enforced on Oscar, Earl, and Alan, and that Marvin was dropped from the roster due to being absent. Due to the astronomically large solution space, it's dubious to extract high-level meaning from this lineup other than "it achieves the highest strength score for the specified minimum satisfaction". Still, by brute force, the program generates a lineup that seems to have some real thought behind it:

  • Andrew was assigned to pitcher due to his strong throw accuracy, preference for the position, and the added fact that it was otherwise unpopular in the survey
  • Igor was assigned to shortstop due to being the all-around strongest player, suitably assigned to the most important defensive position, which he fittingly prefers
  • Isaac, who has the strongest glove, was assigned to the "hot corner" of third base, a low-weighted position, but one he enjoys despite his weak throw accuracy
  • Stronger runners were assigned to the left-hand side of the outfield, which sees more line drives that the right side
  • Weaker runners were assigned to the right-hand side of the outfield, which sees more pop and fly balls than the left side

No comments:

Post a Comment