Weekly Head Voices #130-2: Direct experience dopamine.

Photogenic and non-camera-shy dragonfly I met in Paarl over the weekend.

As I went through my notes to extract material for this week’s post, I noticed a small discrepancy between the task description for the previous post and the published version: #129 in my notes versus #130 in the published post!

It’s too late now to rename #130, so in this reality I’m just going to have to deal with the fact that WHV #129 will never exist. I have decided to name this edition #130-2 so that eventually (well, in about a week), we will be back to uninflated post numbers. Nobody likes inflation. Except perhaps tyres. And balloons.

Your brain at work part 2: Dopamine and more mindfulness

Ironically, the incorrectly numbered post #130 dealt with the many ways in which our brains fail us every day. (Now that I’ve finally gotten around to installing the WP Anchor Header plugin, we can link directly down to any heading in any post, as demonstrated in the previous sentence.)

At least some clouds do seem to have a silver lining.

Your Brain at Work, the book I mentioned last week, has turned out to be a veritable treasure trove of practical human neuroscience, and I still have about 30% to go. My attempt at meteorological humour above was inspired by part of the book’s treatment of the important role of dopamine in your daily life.

For optimal results, one is supposed to remain mildly optimistic about expected future rewards, but not too much, which will result in a sharp dopamine drop when those rewards don’t crystallise, and a greater increase when they do. For optimal results, one should try to remain in a perpetual state of mildly optimistic expectations, but also in a state of being continually pleasantly surprised when those expectations are slightly exceeded.

More generally, the book deals really well with the intricacies of trying to keep one’s various neural subsystems happy and in balance. Too much stress, and the limbic system starts taking over (you want to run away, more or less), blocking your ability to think and make new connections, which in this modern life could very well be your only ticket out of Stress Town.

To my pleasant surprise (argh, I’ll stop), mindfulness made its appearance at about 40% into the book, shortly after I had published last week’s WHV.  In my favourite mindfulness book, Mindfulness: A Practical Guide to Peace in a Frantic World by Mark Williams and Danny Penman, two of the major brain states are called doing, the planning and execution mode we find ourselves in most of the time, also in the middle of the night when we’re worrying about things we can do nothing about at that point, and being, the mode of pure, unjudgemental observation the activation and cultivation of which is practised in mindfulness.

In David Rock’s book, these two states are described as being actual brain networks, and they have different but complementary names: The narrative network corresponds to the doing mode, and the direct experience network corresponds to the being mode.

The narrative network processes all incoming sensory information through various filters, moulding it to fit into one’s existing mental model of the world. David Rock describes it in the book and in this HuffPost piece as follows:

When you experience the world using this narrative network, you take in information from the outside world, process it through a filter of what everything means, and add your interpretations. Sitting on the dock with your narrative circuit active, a cool breeze isn’t a cool breeze, it’s a sign than summer will be over soon, which starts you thinking about where to go skiing, and whether your ski suit needs a dry clean.

This is certainly useful most of the time, but it can get tiring and increase stress when you least need it.

The much-more attractively named direct experience network is active when you feel all of your senses opening up to the outside world to give you that full HD IMAX(tm) surround sound VR experience. No judging, no mental modelling, just sensory bliss and inner calm. Rock sez:

When this direct experience network is activated, you are not thinking intently about the past or future, other people, or yourself, or considering much at all. Rather, you are experiencing information coming into your senses in real time. Sitting on the jetty, your attention is on the warmth of the sun on your skin, the cool breeze in your hair, and the cold beer in your hand.

Again, these two systems are on opposite sides of a neurophysiological see-saw. When you are worrying and planning, no zen for you! On the other hand, when you’re feeling the breeze flowing and and through each individual hair on your arms and the sun rays seemingly feeding energy directly into your cells, your stress is soon forgotten.

Fortunately, mindfulness gives us practical tools to distinguish more easily when we’re on which path, and, more importantly, to switch mental modes at will.

I hope you don’t mind me concluding this piece by recursively quoting David Rock quoting John Teasdale, one of the three academic founders of Mindfulness Based Cognitive Therapy (MBCT):

Mindfulness is a habit, it’s something the more one does, the more likely one is to be in that mode with less and less effort… it’s a skill that can be learned. It’s accessing something we already have. Mindfulness isn’t difficult. What’s difficult is to remember to be mindful.

(If the book has any more interesting surprises, I’ll be sure to report on them in future WHV editions.)

Miscellany at the end of week 5 of 2018

  • The rather dire water situation has not changed much, except that due to more citizens putting their backs into the water saving efforts, day zero (when municipal water is to be cut off) has been postponed by 4 days to April 16. We are now officially limited to 50 litres per person per day, for everything. Practically, this means even more buckets of grey water are being carried around in my house every day in order to be re-used.
  • I ran 95km in January, which is nicely on target for my modest 2018 goal. Although January was a long month, and Winter Is Coming (And Then We Run Much Less Often), I am mildly optimistic that I might be able to keep it up.
  • Python type hinting is brilliant. I have started using it much more often, but I only recently discovered how to specify a type which can have a value or None, an often-occurring pattern:
from typing import Optional, Tuple
def get_preview_filename(attachment: Attachment) -> Tuple[Optional[str], Optional[str]]:
    pass
  • On Wednesday, January 31, GOU #3 had her first real (play) school day, that is, without any of us present at least for a while. We’re taking it as gradually as possible, but it must be pretty intense when you’re that young (but old enough to talk, more or less) and all of a sudden you notice that you’re all alone with all those other little human beings, none of which are the family members you’re usually surrounded with.

The End

Thank you dear reader for coming to visit me over here, I really do enjoy it when you do!

I hope to see you next again next week, same time, same place.

 

Weekly Head Voices #128: Water water everywhere, but not a drop to drink.

Hey friends, welcome back!

We have to talk about the water situation, seeing that Cape Town is now in the international news as being on track to be the first major city EVAR to run out of water.

In short, if it doesn’t rain in substantial amounts during the coming three months (which history and projections say it won’t), the municipal water supply will be shut off on April 21, a date festively referred to as Day Zero.

This means when we try to open any tap, no water will come out. This situation might continue for quite a while, which is pretty intense.

On that day, we will be celebrating by dressing up as Kevin Costner and running around barefoot shouting “NOTHING’S FREE IN WATERWORLD!”. Those who are not big fans of Kevin are allowed to dress up as Imperator Furiosa.

At my house, we stopped watering our garden with municipal water months ago. We installed a grey water recovery system: Shower and bath water ends up in the only remaining green corner of the garden.

We also installed a rain water recovery system three months ago, which has fortunately enabled us to collect a few thousand litres of rain water via the rerouted gutters and pipework from the roof. This water we will probably use after Day Zero to be able to wash and to flush a toilet now and then.

(Flushing frequency has necessarily decreased significantly. Around these parts we now have the saying: “If it’s yellow, let it mellow. If it’s br***, flush it down.” Please excuse the mental graphics.)

We have been managing to keep our use of municipal water under the requested 87 litres per person per day. Starting on February 1, we will have to stay consistently under 50 litres per person per day, including drinking, cooking and washing. I guess 2 minute showers were wasting too much of my time in any case.

I have to do more research and corroboration (fingers are being pointed in all directions), but it seems the fundamental issue is not so much the current drought alone, but to a large extent mismanagement by both local and national government. It’s complicated, and politics is involved, so read at least this (otherwise good piece, but author is a DA / local government apologist), this (DA / local government IS to blame) and this (a longer, more balanced piece) to start with.

That being said, I am happy that a large part of the populace has become much more water efficient. If we get through this, in spite of “this” being called “the new normal”, I hope that we retain our mad Dune-grade water saving skills.

With that out of the way, it would be sort of anti-climactic for me to talk extensively about what-I-did-last-week, so I’m going to limit it to a REAL bullet list (ping me in the comments if something interests you):

  • pipenv is the bee’s knees, I have switched my non-miniconda projects.
  • convincingly but fortunately only temporarily locked myself out of my one laptop due to TCG-Opal hardware encryption, UEFI32, UEFI64 and legacy boot incompatibilities. I’m getting old, I used to NOT lock me out of my laptop in my sleep.
  • A compulsive twitch made me fix years of old-style broken youtube shortcodes using the wordpress regex plugin. The regexp you are looking for is /\[youtube\](.*)\[\/youtube\]/ which you can replace with \1.
  • People dislike really smart leaders. See water crisis above for one possible reason why this is a bad thing.
  • In spite of having invested a significant amount of time in deciding on the Office UI Fabric React components for my most major side-project (#38465 if you’ll recall), I switched to Semantic UI React (which was also in the running, together with Palantir’s blueprint, HP’s grommet, Alibaba’s Ant Design of React and more) at the last minute. I am happier now.

That’s it from me for now. Have fun this week kids, I hope to see you soon!

 

Weekly Head Voices #102: High on life.

The week of Monday January 11 to Sunday January 17, 2016 got off to a brilliant start with a business lunch at Bodega, a restaurant that finds itself on the Dornier Wine Estate. The view looked something like this:

view_from_bodega

… and the company was suitably awesome. (This is not the first time that Bodega makes its appearance on this blog, or in the blog-free suburbs of my social calendar. The company might be different every time, but so far its level of awesomeness has been quite consistent.)

The rest of the (work) week was consumed by extreme nerdery, which is of course the way I love it. Besides more GPU shader fine-tuning (at least once I exclaimed on the Stone Three HipChat, hopefully soon the Stone Three Mattermost,  WITNESS THE POWER OF MATH!, before showing a rendering that was marginally better than the one where the POWER OF MATH had not yet been invoked a sufficient number of times), there was Javascript, d3.js (d3 is another fantastic example of what you can do with vectorised thinking and computation) and Python.

In break time I finally took a closer look at C++14 and beyond and came away super impressed. There’s a blog post in the pipeline on generic lambda expressions, because I think they’re brilliant. I don’t know why I love different programming languages so much, but I do.

On Saturday,  I got really high with one of my besties, a superb gentleman who also goes by the name of A Very Flat Cat. We reached this altered state by the old-fashioned but extremely reliable (and cheap!) method of physically increasing our altitude via ambulation up the west peak of the Helderberg. The walk (a few hours in 35 degrees Celsius…) was exhilarating, and the view from the top awe-inspiring. Check it (click for high-res):

20160116_100314-PANO

I’ve often wondered about the effect of one’s surroundings on one’s mindfulness. This was one of those cases where mother nature, without asking for permission or anything like that, simply brute-forced the being switch with her astonishing beauty. Very grateful I was.

Have a great week friends, see you on the other side!

Closure expressions in Swift

Swift is a new high-performance compiled language designed by Apple. I’ve had some experience using it for an IOS development project, but the language is open source and is already available for Linux.

Some of you are probably able to appreciate the irony of me writing a blog post about Apple’s new programming language Swift, but here we are. :) I am, grudgingly, really impressed by Apple’s good work.

In this post I’m going to chat about closure expression syntax, in the process showing you IBM’s Swift Sandbox, an online tool for experimenting with Swift.

Let’s start with a simple example (slightly modified from Apple’s documentation on Swift closures) for sorting a list of strings in reverse alphabetical order:

// names will be constaint, so we use let and not var
let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]

// function taking two parameters and returning boolean
func backwards(s1: String, _ s2: String) -> Bool {
    return s1 > s2
}

let reversed = names.sort(backwards)

print("Reversed alpha:", reversed)

That’s a complete compilable program in Swift, which you can run directly in your browser by clicking here.

We use let to define a list of strings. Swift is strongly-typed, but in this case it simply infers the type of the names variable from the value that’s assigned to it. MAGIC!

If we were planning to change the value of the names list at some point, we would have had to use var (mutable) instead of let (immutable).

We then define a function called backwards that takes two strings, and returns the true value if the first is larger than the second. In the final let statement, we call the sort() method on the names list, but we pass it the backwards() function, which it will use to compare elements during sorting. Because we have flipped the s1 and s2 variables, we get our list back in reverse alphabetical order.

sort() can be seen as a higher order function that takes the backwards() function as one of its inputs, and uses it to do its work.

Since we’re only using the backwards() function once, it would have been pretty convenient if there were some way to define it more compactly and in-place.

This is exactly what Swift’s closure expression syntax is for. Here’s the above code, with the backwards() function written as a closure expression:

let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]

// closure expression syntax for inline anonymous function:
// { (args) -> returnType in statements }
var reversed = names.sort({ (s1: String, s2: String) -> Bool in return s1 > s2})

print("Reversed:", reversed)

(You can run this Swift code in your browser by clicking here.)

Instead of having to define and name a separate function, we can specify a function in the exact spot where it’s needed, using closure expression syntax i.e.: { (parameters) -> returnType in statements }.

For you Python-heads out there (MY PEOPLE!), the above code can be written in Python as follows:

names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]

reversed = sorted(
    names,
    cmp=lambda s1, s2: 0 if s1 == s2 else (-1 if s1 > s2 else 1))

print(reversed)

In Python, lambda is used to specify anonymous function objects (our closure expression syntax, in other words). The compare function is defined differently, which is why it’s somewhat more complicated, but the principle is the same.

Whilst typing this blog, I downloaded Swift 2.2 from the open source download site and installed it on my Ubuntu 14.04 laptop (the internet is so slow over here, we have to multi-task to stay sane). After compiling both the examples using swiftc whatever.swift, the resulting binaries are about 21 Kbytes each (they are dynamically linked to a number of system libraries, and the 5M libswiftCore.so).

swift-sort-binaries.png

The Swift language is open source, is already available for Linux, has a number of really compelling modern language features of which closure expressions are just one example (other interesting examples include optional types and protocol extensions), is statically typed with good type inference, and has a good compiler. For these reasons, it should be strongly considered for a permanent spot in your compiled language toolbox!

P.S. Yes, I do know that C++ has lambda and auto. I like them too!

Python 2.6 enabled VTK 5.4 Windows binaries

You can always check my Latest VTK Windows binaries page to make sure you have the latest blog posting and hence the latest binaries.  It also links to the “old” Python 2.5 VTK 5.4.1 binaries.

I’ve made available my home-baked VTK 5.4.2 Windows binaries.  These have the new-and-improved version of my python-exception-patches integrated (more about this in a future post; a serious dead-lock has been fixed and as a side-effect, you can now run multiple VTK pipelines in different threads!) and have been built with Visual Studio 2008 (9.0) SP1 on Windows XP SP3 with full Python 2.6 support.  Get the binaries (or my patched source) from the two links below.  You want the binaries if you want to use VTK from Python.

IMPORTANT: you might have to install the MS VS2008 SP1 vcredist_x86 package (free!) if you want to use these DLLs (thanks Jelle for pointing this out).  This might not be necessary if you already have one or more of the MS development environments installed.

Please leave a comment on this blog posting if you use these or just hate them. It’s almost like postcard-ware, but with blog comments. Please also link to this page and not directly to the download location, thanks!

To use this from Python, you need to add the following to your PATH:

  • d:\opt\VTK\bin

You also need to add all of the above to PYTHONPATH, as well as the following:

  • d:\opt\VTK\lib\site-packages

… where d:\opt is the drive and directory where you unpacked the ZIP file.

Once you’ve done this and logged out and in again, “import vtk” should work at the Python prompt. Shameless plug: you can use my free envedit software to do the environment editing. It beats the default XP editing thingy.