Wednesday, July 27, 2016

Using a Simulation to Test a Baseball Question


I often listen to sports radio in the car and recently the talk of the town has been about the Houston Astros, who started the season abysmally but have turned things around lately. At the time of this writing the Astros have the best record in baseball for the past two months. Well, one of the reasons for their resurgence, supposedly, is the move of Jose Altuve from batting leadoff in the lineup to batting third. Altuve currently leads the MLB in batting average and in on-base percentage and is by far the Astros’ best offensive player. The rest of the offense is subpar, with only a couple of other above-average batters.

The rationale for moving Altuve to third is to get him into the “heart” of the lineup: he can drive in runs if the first two batters get on base and can depend on Carlos Correa, who bats fourth and is another above-average hitter, to drive him in should Altuve get on base. Baseball lineups consist of nine players and teams stack the top of their lineups with their best hitters, simply because those players see the plate most often. For example, someone who bats first gets on average 1/9 more plate appearances per game than someone who bats second and 5/9 more plate appearances per game than someone who bats sixth (under the reasonable assumption that the final batter of each game varies uniformly). The argument to keep Altuve first, therefore, is to maximize his plate appearances on the team. The downside of this is that our best hitter has to bat immediately following our worst hitters. In other words, during the middle innings of the game, Altuve often goes up to the plate with one or two outs already and no one on base. We’d rather him bat with the bases loaded and zero outs.

On paper, each approach has its pros and cons, and it’s not obvious which leads to the most runs. Does having the best player bat immediately following other above-average players increasing scoring? I decided to design a simple simulation to find out. My model simulated the scoring for a single team for a standard 9-inning game. I made a number of assumptions to keep things simple:

Players either record a single or an out for each plate appearance
The batting order stays the same for the duration of the game
Players on base only advance one base for each hit
The game ends after 9 innings or 27 outs

For my first design (A), I assigned on-base percentages of 0.500, 0.400, 0.400, 0.400, 0.300, 0.300, 0.300, 0.300, 0.300 for the nine batters, with the 0.300 batters always batting after the 0.400 batters. For the second design (B), I used 0.500, 0.400, 0.400, 0.400, 0.200, 0.200, 0.200, 0.200, with the 0.200 batters succeeding the 0.400 batters. I then moved the 0.500 batter to either the first, third, fourth, or ninth positions in the batting order and simulated 5,000 games for each scenario. The average runs per game are depicted in the table below.



First
Third
Fourth
Ninth
A
2.3668
2.3472
2.309
2.268
B
1.172
1.1868
1.2162
1.1358

Batting leadoff generated slightly more runs than batting third in design A but slightly less in design B. However, over the course of a 162-game regular season, the difference only amounts to about 3 runs and 2 runs, respectively. This difference is relatively insignificant and would likely not change the outcome of more than one game in a season. Interestingly, batting fourth yielded the most number of runs in design B but not A, which gives credence to the idea that a great batter is wasted if placed directly behind exceedingly poor hitters. However, the differential compared to batting first still amounts to only 7 runs for an entire season, which might affect the outcome of only one or two games. Finally, we can visualize the effects of plate appearances by directly comparing batting first to batting last, since the order remains the same in both cases. In design A, batting first yielded 16 more runs over the course of a season, whereas it only netted 6 extra runs in design B.

Generally, the data indicates that there is not a significant advantage to be gained by moving the best batter away from the leadoff position into a different spot in the lineup. However, my model was very simplified and did not take into account factors such as walks, extra-base hits, base running, multiple-out plays, sacrifice bats, and variations in hitting, pitching, or fielding depending on the situation. An actual sophisticated model would take into account walk rate, slugging percentage, base running, and performance with runners in scoring positions for each player, which could make the data more robust. Meanwhile, variations in pitching and fielding resulting from different in-game or out-of-game situations would likely average out over the course of a season.

Traditionally, teams prefer to put their best offensive players, especially those who hit for power, in positions three through five, and rarely will they have them leadoff. Part of the reason could be psychological: teams prefer that their lineups escalate in threat level instead of featuring the best player first in order to put pressure on opposing pitchers. Or this approach could be used to provide a slight morale boost to the batting team and its fans. Whatever the reason, the data seems to be relatively indifferent towards batting order, so there are likely some intangibles at play. 

Monday, July 25, 2016

Leveling Up in Hearthstone


I really enjoy card games of all varieties and for this post, I will talk about a game I play regularly, Hearthstone, and some interesting aspects of what constitutes a good Hearthstone player. Hearthstone is Blizzard Entertainment’s online collectable card video game, similar in concept to Pokemon TCG, Yu-Gi-Oh, or Magic: the Gathering, in which you play against one other person and win by achieving a certain objective, in this case reducing the opponent’s health to 0. There are two game modes: Constructed, in which players choose cards for their decks from the entire card pool, and Arena, in which players are randomly offered a small set of cards to choose from. The gameplay rules are identical for both, and thus many of the basic skills are transferable, but the experiences are vastly different. In Constructed, players can expect to encounter the same decks with the same cards over and over, whereas in Arena, every deck is random and thus, every game is different.

From my description it should not be surprising that I am an avid Arena player who occasionally dabbles in Constructed (mostly for the end-of-month rewards). What I love about Arena is how each game is like a new puzzle or maze to navigate through. There are countless decisions to make throughout each game, and you can never be exactly sure what the best play is, kind of like life. At this point, I have become a machine at Arena and will reflect upon some of the level-up moments that helped me get to this point. Whether or not these lessons extend appropriately into the arena of life (I’m terrible) is left as food for thought.

I am going to assume players know the rules of the game and have some experience with card games in general. Obviously, the more experience one has the faster one will pick up Hearthstone. And some people are more talented than others, etc. But Arena is not terribly difficult to become competent at, and so I will ignore innate differences in ability and speak more generally.

The first step to learning Arena is to simply get a feel for how games play out, what cards are good or bad, what tends to work or not work, etc., and this knowledge is gained mostly through experience. Very seasoned Constructed players will almost always struggle with Arena in their first few attempts because they lack general knowledge about the Arena landscape. Fortunately, this knowledge is accumulated over time, almost without effort, as long as you play when lucid.

Once players have some general knowledge of the game, and thus have some notion of what to do, the next step is to actually become a consistently winning player. I think the single biggest trait that separates the vast majority of the player base from those who have the potential to become really good is the ability to plan ahead. Most players make decisions by only considering what’s in front of them, but great Arena players always plan for at least a turn in advance, if not more. For me, this specifically entails envisioning how the board state will develop on my opponent’s turn, and how the board will appear when it gets back to me for my next turn. Interestingly, this process is not difficult at all; it simply requires imagining several small steps for a couple of different scenarios, nothing that a normal person cannot carry out. I strongly believe that anyone can learn to do this. But interestingly, some people are much more inclined to this than others, and the ability is not necessarily correlated with general intelligence. Rather, it’s a type of game shrewdness that many intelligent people may not be predisposed to, although it can be learned over time.

Consistently planning ahead is a trademark of above average players, but the truly great players take this a step further by always trying to maximize their chances of winning. This sounds obvious, but the application is quite nuanced because humans are not rational decision makers. For example, people tend to take the risk-averse route, even if the riskier choice has a slightly higher expected value. People also tend to be overly optimistic when evaluating their own situations. The way this plays out in Arena is that players often choose to play around the worst-case scenario in order to not lose the most, or evaluate cards based on their highest possible upside, which may require jumping through hoops to actually pull off. These tendencies may serve a useful purpose in life, but in the context of Hearthstone they more often than not decrease our chances of winning. Being able to recognize and then overcome these habits distinguishes the great players from the rest.

I want to provide a practical example of how this works. If you play card games often, then you’ve probably heard the expressions “play to your outs” or “play to win, not to not lose”. These phrases are a manifestation of playing to maximize winning. When faced with a difficult decision, simply try to maximize your chance of winning the game (if you like math, think of it as expected value). If you have two or more choices, you can draw a decision tree, make a table, or do some quick math to figure out which option is best. For example, suppose you are in a winning position and are trying to decide whether to play around a specific card. If the opponent has the card and you don’t play around it, you win 10% of the time, but if you do play around it, that number shoots up to 50%. If the opponent doesn’t have the card and you don’t play around it, you win 80% of the time, and if you do play around it, you only win 60% of the time. Now suppose you can estimate that the opponent has a 30% chance to have that card. If you don’t play around it, you will win (0.3)(0.1) + (0.7)(0.8) = 59% of the time, whereas you will win (0.3)(0.5) + (0.7)(0.6) = 57% of the time if you do play around it. If you knew the probabilities perfectly, then the correct decision would be to not play around the card.

The example above was very specific, and in an actual game, you would never be able to pinpoint probabilities with reasonable accuracy. To complicate matters, each decision has to be made in the 90 seconds allotted for each turn. In reality, I consider more than just one variable for most decisions and never make actual expected value calculations. Instead, I rely on my intuition to roughly determine which option leads to the highest win rate. Oftentimes, good players will have a reasonable idea of what the optimal play is just from their intuition. However, to become a great player it is extremely important that the idea of playing to win is at the core of each decision. Intuition is developed from past experiences and habits, and those on their own do not improve over time without proper critical assessment. For example, I may prefer to make a certain play because I am comfortable with it and know from experience that it works most of the time. However, that play may not lead to the highest win rate, nor has it ever, but because my intuition was developed without a framework, I completely overlook the actual optimal play. In this case, I have developed a sub-optimal intuition for making decisions because I did not properly evaluate how each decision would impact my chances of winning from the outset.

Life is oftentimes the same way, albeit more complex. Humans tend to flock to the familiar road and not necessarily to the best path. We prefer comfort, and change can be extremely difficult. But to improve at a game we are familiar with requires constant willingness to evaluate and critique our own decisions. And the same can be said about life.



Thursday, May 5, 2016

A Short Introduction to My Favorite Composer


I have been playing piano since childhood and have had the privilege of studying with wonderful instructors for most of that time. A few years ago, I decided I would learn all 32 of Beethoven's piano sonatas. For those unfamiliar with his works, this is a rather monumental task, especially for someone who is not a professional musician, and will likely take me the better part of my life. Beethoven's piano sonatas are considered among the greatest works ever composed for the instrument and are likely the most-studied and most-recorded pieces as well. They are held in such high regard because they cover a huge range of musical and emotional territory, yet the writing remains consistently splendid from the first to the last. In my opinion, all but a handful are great, and several of them I consider absolute gems.

Now you might think I am simply jumping on the Beethoven train, since he is the most celebrated composer of our time. Indeed, I adore his piano sonatas, but I don't believe they are necessarily better than comparable works of other great composers (for example, piano sonatas by Schubert or Prokofiev). Instead, my penchant for the composer is born from intrigue with his personal experiences. Beethoven experienced particularly poignant pains during different periods of his life. And while he struggled to ever find any peace within the world, he managed to illuminate many aspects of his life through music, and in doing so, speak allegorically of the human condition. In this sense, he was the first true Romantic composer, by using music to delve more boldly and deeply into humanity than anyone before him.

My own identification with Beethoven came with the discovery of his late piano sonatas and late string quartets. By the time he composed these works, Beethoven had already been deaf for roughly two decades. These works were the culmination of years of turmoil, despair, and hopelessness followed by gradual acceptance, gratitude, and embrace. Towards the end of his life, I would like to think that he finally came to terms with his own deafness, finally embraced the opportunity to give something wonderful to the world from a position of weakness. I can only conjecture how he truly felt, but his music suggested a transcendent maturation of one who had surfaced from the darkest depths of life.

Beethoven was raised under the watch of a strict alcoholic father who beat the child regularly and forced him to practice for unreasonable lengths of time. This probably contributed to his developing paranoia and irateness with everyone around him. Beethoven grew up to be somewhat crazy and extremely difficult to get along with, both with strangers and with those who knew him. In particular, he struggled immensely to find love, both romantically and within his own family, and went through a nasty custody battle over his nephew when his brother passed that interfered with his musical output. However, his most defining battle undoubtedly came against the onset of deafness.

Throughout his late teens and twenties, Beethoven had gradually made a name for himself as a budding virtuoso with incredible improvisation skills. During this time, he studied under Haydn and composed a great number of works in the Classical style, many of which went unpublished. What I find interesting is that compared to Mozart and Schubert, who had both composed incredibly mature works before the age of 30, Beethoven's early output was more tempered. While still sophisticated, his early music was largely playful and followed traditional styles. There are some notable exceptions, such as the Cantata for the Death of Joseph II, composed when Beethoven was 19, which contains emotional depth resembling that of music from much later.

It is hard to say how Beethoven would have developed as a composer had his hearing not started to fade. He remained extremely prolific into his early thirties, as he wrestled with his encroaching deafness and the quick evaporation of his own performance aspirations. His music took a turn during this time -- some of his works were noticeably more tumultuous and somber than earlier. At the same time, Beethoven began to take more and more liberties with musical structure, often breaking away from traditional approaches. This aspect of his music, I believe, would have occurred inexorably as a result of his increasing freedom (he was the first notable composer to not be employed by a court) and musical maturation.

One of the most interesting discoveries came following Beethoven's death in 1827 of a letter he wrote in 1802, now known as the Heiligenstadt Testament. It spoke of his emotional response to his deafness: the initial embarrassment, the ensuing frustration, and ultimately the overwhelming sense of isolation, as he no longer believed he could operate normally within society. In the letter, he briefly mentioned ending his own life but decided that his "art" was too valuable to not pursue further. Here, his pride, which caused him much despair, ultimately spurned him to continue pushing onward as a composer.

This testament was a watershed moment in the composer's life. By putting down in ink the rationale for his decisions, which he intended to be read after his death, Beethoven embarked on the gradual process of allowing his own physical and emotional well-being to play second fiddle to his quest to create music. He recognized his supreme musical gifts and decided at that moment that he would endure all hardships for the sake of using those gifts. As music truly became the reason for his existence, he poured increasing amounts of personal emotion into his compositions, which became a primary means of communication with the outside world, a world that could not relate to his troubles.

The last two decades of Beethoven's life yielded some of the most inspired music we have ever heard. Slowly his writing became more complex, more innovative, and more introspective. Among his greatest compositions exist the common themes of resolution and triumph. For example, the last movement of his final piano sonata elicits images of innocence, turmoil, desolation, loneliness, yearning, and tranquility, corresponding to Beethoven's own life trajectory. The piece concludes with the simplest and purest cadence, a sigh from the composer that speaks of his own acceptance of his life. Beethoven has won the war because he has come to terms with the things he cannot change.

What I love about this story is how an extraordinarily prideful and gifted man is humbled to the lowest point and then undergoes a journey to find peace, not through conquering his condition, but through reevaluating his identity. He must constantly grapple with not having what he wants in life, in a sense becoming a never-understood hero who suffers for the world. The music that spawns from such struggles reflects upon the innermost depths of his soul and invites audiences everywhere to experience that transcendence as well. Ironically, one person who will never hear performances of such wondrous music is the composer himself. But Beethoven resigns himself to this fact, and in doing so, lets us know that choices are more important than gifts.

Monday, May 2, 2016

Our Inner Demons

A framework to address turmoil


As I’ve dealt with inner turmoil, I’ve poured through many articles and stories of how others approach their struggles. This post is largely shaped by the opinions I have gathered, and I apologize that I will not be citing where I first discovered many of the ensuing ideas.

What causes the most discord in my life? Why do I sometimes lack motivation, hope or joy? Recently I realized that instead of just pinpointing what my struggles are, I need to understand how they take effect and operate. In essence, our innermost demons work through a discrepancy between our reality and expectations.

Expectations are formed through years of experiences and exposure to stimuli. Influences from family and friends, messages from the media, and self-developed ambitions all help shape what we expect from life. For example, growing up we often hear about the glory of the American Dream (apparently, this is also the Chinese Dream because my parents told me the same thing). Over time, we may come to expect to live in a cozy two-story house with a loving family and a stable job. After continued exposure, this idea becomes an expectation and subconsciously, even a desire. The more it gets reinforced, the stronger the expectation becomes and the more difficult it is to challenge.

Unfortunately, life does not always follow our expectations, and sometimes not due to a fault of our own. If we suddenly find ourselves unable to live the American Dream for some reason, and not just at this moment but indefinitely, then our entire identity gets challenged. We are sad in the present because life is not what we want it to be. Moreover, we feel pessimistic about the future because life may never be what we want it to be. Travelling down this train of thought can lead to feelings of despair and hopelessness, depending on how important the expectation is.

How do we to mend this wound in our identity? Besides denial, we might simply choose to ignore the issue completely and focus on other, more merry aspects of life. Again, depending on how dear the issue is to us, this tactic may not work very well. Imagine working your whole life towards a goal, perhaps as an aspiring athlete or artist. In an accident you suffer an injury that effectively ends your career. How do you reconcile this new condition preventing you from fulfilling your lifelong dream? Can you simply ignore the fact that everything you worked for has come to an end?

We all have to deal with unfulfillable expectations at some point in our lives. I think one way to handle a crushed dream is to simply let it go, but this is a lot easier said than done. When an idea becomes ingrained in our minds, not only do we have to undo years of habitual thinking, but we also have to fend off the external pressures that continue to fuel the idea. How difficult must it be to come to terms with not being able to see again, or not being able to have kids, or only having a few months left to live? Especially when all around we see others live the type of life we want, or others continue to demand from us the one thing we can no longer achieve.

Shedding our old expectations in order to form new ones can be among our most difficult yet transformative experiences. So how do we let go? First, accept what we cannot change and do not allow ourselves to ruminate on the past. Second, imagine a joyous and fulfilling life with the new expectations. Eventually they’ll come to form our new sense of identity, one that matches our reality. 

--

Expectations matter a lot because they help shape our outlook on life and thus our happiness. Failure to meet high expectations can lead to disappointment and fulfillment of modest but genuine expectations can bring joy. However, a warning should be made against artificially setting a low bar. Studies show that optimism in general brings many benefits whereas constant negativity or self-deprecation has many drawbacks. I won’t go into details here, but generally optimism is correlated with higher levels of resiliency and happiness.

So how do we separate the good optimistic expectations from the unfulfillable life-draining ones? At times it’s obvious, but sometimes the line is not clear-cut. Studies show that most people tend to overestimate their own situation, and thus most expectations are based as much on imagination as reality. Furthermore, we see examples of visionaries refuse to waiver from their goal to eventually accomplish the seemingly impossible. But, for each success there are many more who fall short.

Perhaps one useful metric to examine is how our expectations affect us. Do they motivate, inspire, and energize us to face our challenges? Do they provide a sense of purpose and pride with each new achievement? Or do they sap our energy, cause us to regret our past, dread our future, or even hate ourselves? At that point it may be time to let go.

--


This is a great talk on how happiness can emerge through uncontrollable circumstances: https://www.youtube.com/watch?v=4q1dgn_C0AU