📚 node [[meditation for programmers]]

I've been meditating regularly for about six months now, doing it daily for around the last two. I'm far from an expert, but at this point I'm convinced both about the absolute benefits of meditation and its relative (opportunity-)cost-benefit ratio, so I feel like it's an appropriate time to write down my thoughts as they are.

I'm writing this with "programmers" in mind as my audience, although "computer enthusiasts" could be used instead equally well; if you like computers and have some level of interest in how they work, and you're curious about minds, you should be able to get something useful or interesting out of this. If you don't, please let me know and I'll try to improve the piece.

Sidebar: on our models of the world and our models of the mind

There is a common thought in the fields of theory of mind/psychology/neuroscience, and that is that each generation uses the models they are familiar with to try to understand the brain. Our generation has computers, and we have taken a liking to them; so it is not surprising that a lot of our contemporary thinking on cognitive science starts from the assumption that brains are meat computers.

In many ways they are, of course, but there is a risk in pushing the metaphor and the model too far. Some computer-like models may just make sense to us because we're immersed in a reality in which computers are ubiquitous, and may look quaint in a few centuries once the prevailing paradigm shifts. Imagine quantum computers change the world and displace our current digital computers to a significant enough extent; then our model of thinking about the universe and the mind may shift naturally to them resembling quantum computers. People looking back to us and our quaint digital computers would perceive us as wrong as us looking back to Medieval physicians and their theory of the humours.

I think this is the reason that some neuroscientists work towards finding neural correlates of our experiences; our experiences are, to some extent, mediated by our models, but finding the minimum sets of brain activity that correlate strongly with a subjective experience seems to be a good way to "corroborate" some of our cognitive models -- make the argument that they match how the brain actually works, at least on a high level structural sense.

This is all to say that this post is, basically, the result of applying a slice of neuroscience and our models of computing to the mind as perceived through meditation. It's not original work; it is my reading of common positions that smarter people than me have arrived at. It is hard to debate whether it is true or not, given that we're talking about models. So, caveat emptor. But I hope someone else can find it useful, which is the most we should ask for from most of our models.

Meditation is a tool for introspection

After that long preamble in which I lost 50% of my readers, here's the deal: meditation is a tool to train attention, awareness and meta-cognition. Let me define those so we're sure we're on the same page:

  • Attention is the sense of focus you can direct by applying willpower. You probably know what I mean: you can direct your attention to an object or task and prioritize it over all others, at least while your attention lasts. As usual, our visual system provides a very good example (or is it a metaphor?) for this cognitive phenomenon: you can focus visually on an object and see it in detail, while the surrounding field of view is sort of blurry.

  • Awareness is whatever your mind is conscious of that you are not focusing on. In the field of view example, everything but the object of focus that you can still see is in your field of awareness. I've slipped a reference to consciousness here and it's problematic (we haven't defined it) -- bear with me here, we'll get back to that later.

  • Meta-cognition is the skill of directing attention and awareness to the mind itself -- your thoughts, feelings and other mental processes.

Here's the kick: we all have these tools. And we are all thinking, all the time. We are just not meta-cognitively aware of it. It takes effort and skill to be aware of more things, more of the time. It takes even more effort to be able to direct our mental processes instead of defaulting to doing whatever happens next.

Now, this is a model. It may or may not resonate with how you intuitively think (or feel) about your own thinking. In this model, though, meditation is the tool that lets you build up these traits and skills. Meditation is exercise for the mind, like other kinds of learning; but it is more directed to meta-cognition than other kinds of learning.

Meditation also lets you see for yourself. When you sit down and meditate, you learn how to observe your mind. What you find will likely surprise you. You will learn how to notice attention, how to notice awareness, how to notice your mind drifting -- all the time at first. Then you will learn how to accept its drifting, and then how to control its drifting, and finally how to stop its drifting and direct your thinking.

The actual process of meditation is deceptively simple: you try to focus on your breath (or, later, a different meditation object). You discover you failed -- your mind drifted somewhere else. You acknowledge that thought, reward yourself by appreciating the fact that you realized you had drifted, then go back to the meditation object. Repeat.

Meditation has been described as first person science because of the fact that it's based on insight, observation and experiments. You learn by seeing how you fail, accepting it and then correcting it. But, of course, this could all just be a model that you're learning and not ground truth reality; you are using introspection and not advanced technology and brain scans (although, of course, such studies of meditation and its benefits exist).

Getting root

I promised you a tie-in with computers and I'll try not to disappoint.

I do currently believe our minds are computers. They are more than that, perhaps, but it seems to me (and others) that they are at least that. It could be a mirage of the times, as I mentioned earlier; it could be that, if I were writing this in a steampunk parallel universe, I would be equally convinced our mind is in many ways like a steam machine. But I think computation might be special in this universe; we are where we are (us, humans, apex species) mainly because of how we think (as individuals and as groups), and not because of physical attributes (although we are good enough in those aspects as well). And thinking is computation.

Our minds compute all the time; we think all the time. You do not notice it often; thinking just happens, and usually you only have to pay attention when something goes wrong or is somehow surprising. A lot of the computation is unconscious.

The process in which something catches your attention is the correlate of a computer interrupt; some subsystem declares its output to be of interest, or needs inspection for being able to resume regular processing, and raises an interrupt. The mind then addresses the interrupt as well as it can and tries to carry on.

But the mind is itself a complex, distributed system; not a monolith. Meditation has its roots in Buddhism (and Hinduism), and Buddhism has had a modular theory of the mind since about the fourth century C.E. What I got my hands on, of course, is a modern interpretation of it (see references section), but the roots are definitely quite old and seem sound to me. While researching this area I found it surprising how in many ways the Buddhist theory of the mind and Minsky's Society of Mind have significant overlap.

Each sub-mind (adapted from the Buddhist categories) or agent (in Minsky's parlance) mostly operates unconsciously. I've been thinking about them more and more as Unix processes, chugging along in the background. These processes can generate interrupts (raise attention). Some of these interrupts bring them to the foreground (into "store-house consciousness" in the Buddhist tradition); while they are in the foreground, they execute consciously.

Put another way, consciousness is an interface that processes use to interact; in one canonical definition, it is the place and process where information is integrated. You can picture this setup as akin to that of a complex shell command doing processing through subprocesses and pipes and outputting the result of its computation at the end. Or, alternatively, you could think of it as a chunk of shared memory. Either work, I think, and the analogy is fuzzy here; consciousness is one of the perennial hot topics in psychology and neuroscience, so we won't settle it here.

Consciousness can also be seen as a succession of slices of attention. The mind probably does not really have a fixed clock cycle like our binary computers; the brain is both actually very slow to propagate impulses and ridiculously parallel, so definitely not your run of the mill simple-but-fast Von Neumann architecture. But through meditation you can become more aware of the fact that the mind does seem to have something like a clock, or at least a series of sequential slices of attention that can be distributed -- assigned to mental processes. This seems akin to the function of the OS scheduler in our digital computers: the scheduler assigns slices of CPU time according to a policy, which enables (for example) co-operative multitasking. If you support interrupts (and both modern OSes and our minds usually do), you also can leave the door open to urgent messages from subsystems getting ahead of their place in the queue when needed: think of the evolutionary advantage of the visual subsystem communicating the fact that it just saw something shaped liked a snake, as quickly as possible.

Now, if you accept that our minds have something like a scheduler, and our thought makes use of resources that sub-processes have to compete for -- what difference does it make?

Well, meditation tells you that you can first observe how your system works: what kind of processes catch your attention repeatedly? How many slices of attention are you investing in practice in each process? Does the distribution match your expectations?

Then, and more importantly perhaps, it can show you how to change the system. If consciousness is at all like a shell, or shared memory, meditation can get you root.

Tuning the system

One of the tenets of meditation is that meta-cognition influences cognition: if you find yourself lost in thought, and you reward yourself for it while also correcting your attention, over time your unconscious processes will learn to make you (and themselves) less distracted and follow your conscious will.

If you're trying to focus on an activity, you usually don't want your sub-minds to distract you with irrelevant information. You don't want to remember the silly thing you said yesterday, and you don't want to worry about the other stuff you need to do later; worrying is only useful if you do something about the thing that worries you (for example, solve a problem or prepare a solution). But worrying about something when you're trying to focus on something else is often counter-productive; it is better to solve the task at hand and then focus on the next. Put another way, there is a context switch cost between mental activities, and too many interrupts actually reduce the effective throughput of the system. Switching all the time due to worries and irrelevant interrupts just isn't the best possible behaviour. More importantly, though, worrying does not feel good. A distracted mind is usually an unhappy mind, and most people prefer to be happy.

This mismatch is present because, out of the box, we all run with our "natural" scheduler; whatever the combination of our genes, our upbringing and our personal experiences left us with. Our genes probably count a lot here; humans evolved being worried and unhappy, living meal to meal in small groups before the dawn of culture. When you're fighting for your survival daily, relaxing probably doesn't get you far; you want to react to every stimulus as fast as possible and accumulate resources without bound. Most of us now live privileged lives in post-industrial society, though, and it is easily arguable we can now do better than our natural scheduler.

I wrote a very simple toy OS with a toy scheduler once for a CS class, and I enjoyed it a lot. You'd have to do the same for your own hobby OS if you coded it; if you have only N processors and M>N processes that want to run, you need a scheduler.

So, what's the easiest scheduler you can implement that works, in the sense that every process gets to run eventually? Probably a random scheduler: for each slice of time you want to assign, choose a random process and run it. The nice thing is that it doesn't require any memory; you don't need to know anything about the past to choose a random process. It's cheap. The bad part is everything else: it is, of course, quite terrible as a scheduler. Processes might take long to schedule. Useless processes may be scheduled time after time while processes that need CPU time starve.

Through meditation you might find that your built-in scheduler, although not as bad as random, is uncomfortably close to it at times. I did. My mind is all over the place; most minds are. I lack focus. When I think I'm focusing I'm getting distracted ten times a minute, at least.

What if you could improve your scheduler, bit by bit? Tune its policies?

Meditation starts by letting you become aware of (some of) your context switches. Eventually you gain some control over them; you may start to successfully preempt low value ones. Eventually you may be able to override the scheduler completely for some length of time; think of dedicating all available attention slices to the task you're trying to solve. In Unix terms, you get nice. This kind of override is an evolutionary trade-off, so it makes sense you would have to work hard (practice) to get this mental tool. But, as long as you know your apartment is snake-free, it is likely advantageous.

Fixing bugs

There is another tie in between meditation and programming, and it's perhaps more obvious: we are all a collection of programs. Most of our programs run as unconscious processes -- the processes we discussed earlier. Of course not all of them run at the same time; they get instantiated as needed, or as prompted by other programs.

This structure can be spotted in our own thinking and feeling through meditative introspection. We react to things so very often; we actually spend most of our lives just reacting. But what is reacting? It is, very often, to follow unconscious programs.

Now, don't get me wrong. Unconscious programs and processes are good. We depend on them, and they are often solid. Some of them evolved; some of them we picked up in our early age. There is a saying in AI about how "easy is hard": when people were starting out in AI they thought teaching computers to play chess and do logic was going to be the hardest thing to do. In reality, though, that was cracked way before we could teach computers to do simple stuff like object recognition (now finally advanced through deep neural networks) and robots how to move reasonably (still very much a work in progress). This is because a lot of our unconscious programming, and consequently a lot of our brain, is dedicated to "simple" things like movement and perception. Because we assess complexity in our consciousness, we miss the point often.

But some unconscious programs we host are definitely very inefficient. They carry baggage -- evolutionary and personal. Consider your natural reaction to thinking about a problem: often you cannot think about a problem without also feeling unhappy about it. Feeling anxious, or unhappy, or stressed -- they are all part of the program; there is an if-then-else that points to a stress response, and your consciousness is executing it.

Meditation lets you introspect (debug) and recognize that some of our reactions -- some of this unconscious programming -- are not necessary. They are optional. Yes, it's hard to think of something upsetting without getting upset -- but you can learn how to do it. Yes, it's hard to think of something painful without feeling pain -- but you can make great strides in at least tolerating that mental pain by recognizing it is mental, and separating it from the stimulus that caused it or the thoughts that you're having about it.

This detachment also allows you to break loops. Our thinking is full of loops. Loops can work as reinforcement, but some loops are clearly negative and counterproductive; you want to be able to break out of those. Consider anger, a quintessential suboptimal state: anger by itself lasts only a few seconds. If you ever spent more than ten to thirty seconds angry: you were doing it to yourself by thinking about your anger, keeping it alive, running the loop. There is a reason why "take a deep breath" is common advice: focusing on something else breaks the loop.

Once you learn that something is optional, you can stop doing that automatically. Stop reacting, and start managing your actions. Keep the useful thought or action, discard or deprioritize the suffering.

Fix the bug.

References

I'm not an expert, just an enthusiast. You should considering going to the source if you're interested. These are the books I'd recommend to anyone wanted to dive into these topics.

  • Yates, John, Matthew Immergut, and Jeremy Graves. The Mind Illuminated: A Complete Meditation Guide Integrating Buddhist Wisdom and Brain Science for Greater Mindfulness. 2017. Print.
  • Minsky, Marvin L. The Society of Mind. New York: Simon & Schuster Paperbacks, 2007. Print.
  • Harris, Sam. Waking Up: A Guide to Spirituality Without Religion. New York: Simon & Schuster, 2015. Print.

If you want to try meditation, I'd recommend Sam Harris' Waking Up app. It's subscription based, but worth it. Other apps such as Headspace are also good starting points, but in my experience Waking Up is superior.

📖 stoas
⥱ context