Sunday, 5 April 2015

Reflections

CSC148 has been, hands down, the hardest course I have taken thus far at U of T. Having taken Calculus last semester, I figured that 148 would be an enjoyable vacation from the rigours of Math and the other demanding Life Science courses I have been enrolled in. Programming is, after all, pretty fun right? In spite of the level of challenge this course entailed, the additional challenge posed by the strike,  and the litany of apparent impasses I hit throughout it's duration I still recall wanting to work on my Computer Science assignments more so than I did my other courses. And I have really come away from it with important cognitive developments.

Aside from an introductory experience to concepts in computer science, my biggest takeaway from CSC148 is a meta-cognitive one relating to problem solving. I have not only learnt (and relearnt) the importance of how we approach problems, but also specific strategies and habits that I believe will be of lasting import. 

The general theme of this meta-cognitive lesson is how and when to let go, especially when dealing with a highly complicated and challenging problem that has emotional counter-parts in frustration, anxiety, hopelessness and so forth. There are various points in the long-term process of tackling such a problem that the only pragmatic choice is to forfeit effort, and either retry later or divert attention to a different problem. I will explore a couple that I specifically recall as being vital to my completion of the assignments and to learning how to write recursive functions. 

When speaking with more experienced programmers, one gets the sense that they have a lower degree of confidence in their cognitive faculties than oneself. Substitute "realistic" for "lower", and you have a more accurate view of the psychological picture. It is incredibly important to have a very acute sense of your cognitive limitations in any given scenario: Willpower and computational capacity are both limited, and there is absolutely a diminishing returns point that can be passed with insufficient awareness. This diminishing returns point can actually show up somatically as a sense of muscular strain behind the eyes, and longer-term as substantial cognitive fatigue. This happened to me after A2 and Term Test 2 and I believe that, now, I would be extremely less likely to suffer that same misfortune. 

One concrete lesson is what I call "black-box" problem solving, which is vital to recursion. To avoid thinking out a full trace of what the computer is doing each time you would like understand a fraction of what it is doing, it is important to treat objects and methods like black boxes. You consider what goes into and what comes out of these boxes, but trust their implementation enough (at least for the time being) to avoid pulling it into conscious deliberation. This kind of thinking applies to designing classes and functions, where abstract algorithms have to be designed without excessive distraction from thoughts about how each step will be translated into code. If one part of the system of black boxes is not doing its job, you can visit it to the exclusion of the others. In this way, your mind remains sharply honed-in to one problem, instead of scattered about many in ways that strain working memory. In cases where the problem does get too complicated, but a full-trace is required, drawings can take some of the load off of working memory and facilitate creative associations. 

Another concrete lesson is simply to take breaks. There has been a fair amount of neuroscientific and psychological research into the role of rest in creativity and insight problem solving: Higher resting levels of activity in association cortices (Andreasen, 2011) and reduced outward-orientation as being correlated with insightful "Aha!" moments (Kounios and Beeman, 2009) are two such examples. Anecdotally, I can also speak to this. The relative ease with which my mind would "figure it out" when I had taken a break, especially if that break was fun and rejuvenating, was a replicated experiment. Counter-intuitively, I solved Minimax Prune the morning after forcing myself to go out and drink with friends (against my initial instinct to stay in and continue chipping away). 

Lastly, I learnt that persistence does, in context, pay off. After repeatedly doubting my choice to go with Option A for Assignment 3, in spite of a dysfunctional Minimax from A2, I got Minimax and all of its optimization classes passing all Unit Tests this morning (praise the extension). If I had worked ahead on A3 with a killer-instinct, like I did with A2,  I doubt I would have figured it out...and I know I would have been left depleted for finals. But calm, collected, and calculated persistence is exactly the sort I learnt from CSC148.


Works Cited

Andreasen, N. C. (2011). A Journey into Chaos: Creativity and the Unconscious. Mens Sana Monographs, 9(1), 42–53. doi:10.4103/0973-1229.77424

Kounios, J., & Beeman, M. (2014). The cognitive neuroscience of insight. Annual Review of Psychology, 65, 71-93. doi:10.1146/annurev-psych-010213-115154


Thursday, 2 April 2015

Revisitation Of Minimax (The Official "Revisitation" Post)

Two weeks ago I documented my apparent triumph over Minimax, only to find out that it's finality did not survive the scrutiny of doc tests and compatibility with A3 optimizations. At this point, I would like to offer some concluding remarks on a (still) incomplete Minimax/A3 and about the learning experience Minimax has entailed for me. In the future, when I think CSC148 I will think Minimax, likely as some personified entity the likes of which will reveal itself as this semester is consolidated in memory and more perspective develops. However, in the mean time, I still think I have a few words to say.

Technically, I am still unsure of my code. I have managed to pass all official Unit Tests except for one, which appears to have been elusive to other students (see http://adamosslog.blogspot.ca/) for reasons not directly related to Minimax's effectiveness. Specifically, this involves a winning start after the Unit Tests generates a Tippy grid. Debugging this last test will have to be a patient, clever trial-and-error process that really has to factor in all of the possibilities. The problem arising from the TippyGameState code is a best case scenario, with a worst-case being some deep-seated flaw in Minimax that will require a complete revamp. My guess is either the latter or a minor tweak in Minimax; it seems unlikely to pass all Subtract Square tests and be completely off.

Of course this begs the question: Why am I still pursuing A3 with an incomplete Minimax? There are several contributing factors here, but the primary one is simply that I wanted to. I got interested in AI search algorithms, have a persistent disposition, and really did not think that the finish line was too far off. I didn't seek enough help for A2 so I factored in that, with more help, I would be able to crack Minimax quickly and get on to the optimizations. Minimax itself proved to be a challenge even for helpful TA's, with the strike obviously factoring in to the level of preparation they had for A3 as well as the available aid for my initial stab at Minimax in A2. By the time I realized what I had gotten myself into, I was too close to the deadline to restart (creating a whirlwind of stress, for 6% of my mark, in a sensitive time before finals).

In the end, the real mistake I made was  assuming that my Minimax worked before Unit Testing, thus allocating my resources to optimizations of a flawed foundation. However, I still believe that I stand on optimistic grounds. Currently, my Minimax is one Unit Test away from full pass, the code of my optimizations makes perfect logical sense (evaluated by TA third-parties), was designed for a Minimax that isn't too far off of my latest version, and I have learnt an immense amount in a process for which transient regret ("I should have taken Option B!") is regularly replaced by a more productive process-orientation that leaves me confident that I'll bounce back from whatever negative consequences I may have accrued.

To address some algorithmic and implementation details: Two posts ago I mentioned what I perceived to be a genuine stroke of insight about the way Minimax had to function. With my recursive "score checking" in a get_score function, I believed that its base cases had to examine two moves ahead so that each full evaluation only looked at special opponent cases where the opponent played themselves into a loss, then made a recursive call on the next GameState where the computer was the current player. This was based a real misunderstanding of Minimax, which I rectified via discussions with Professor Heap and some "rigorous" hours paroozing YouTube. Minimax is supposed to make its simulated opponent as savvy as possible. In traditional versions of Minimax floating around the web ether, there is a "Minimizer" and a "Maximizer" (hence the name "Minimax") that take turns. The Maximizer's possible moves are whatever the Minimizer serves up from its possible moves, and vice-versa. This sets us up straightforwardly for pruning: The Maximizer sets a lower boundary for what values its will accept from calls to Minimizers, thus allowing us to recognize when to stop computing values the Maximizer will ignore anyways. The Minimizer also sets boundaries in an analogous manner.

The Minimax of CSC148 is most usefully thought of in terms of +1/-1, instead of a Maximizer and Minimizer, but a similar logic applies. As such I set out to create a get_max_score and get_worst_score functions to represent the competitors, then collapse them both into a _get_score helper that took a parameter for either +1 or -1. _get_worst_score lacked that parameter, simply returning _get_score(state, -1).

Upon failing multiple Unit Tests, I began to clean the code up. Humair Kahn and his assignment partner were incredibly helpful here, pointing out a HUGE mistake I was making (born of an overly-ambitious attempt at A2). I was incorporating bits of pruning into my original Minimax without realizing it!! get_score stopped computation upon seeing its first +1, and suggest_move returned the first move leading to a GameState with a +1 score. This created a huge headache for me in A2, and is illustrative of a general problem I have with academic assignments: Over-complication. Computer science, at the moment, is challenging for me in the way that Philosophy was when I initially decided to major in it (one degree ago). Simple, structured thought is more difficult for me than scattered creativity. Interesting research in Neuroscience and Psychology actually points to trade-offs between single-pointed attention and creativity (often associated with open attention and wandering thoughts), with the challenge for me being the former. Comp sci is a great exercise in that, and actually helps me productively channel creative thinking.

After dumbing down my basic Minimax to a version that straightforwardly fit the recommended algorithm in A2, I am now the mere Unit Test away from throwing my arms up and climbing atop a tall structure in my underwear. If that ends up happening or not, I have no regrets about the choice to attempt closure with Minimax. It has been bumpy, frustrating, but never boring.