Thursday, 30 May 2024

How to rule the universe: why I should have learned Git way earlier

A relevant xkcd:


When I first encountered Github as a wee lad, the only thing I knew was how to clone, pull, and push. If anything went wrong, I would genuinely delete everything and start over as I was sincerely clueless how this all worked. It seemed all too complicated. I'm glad I'm not the only one who felt that way.

Imagine my surprise when I work through learngitbranching, perhaps 10 years after seeing Git tools for the first time, and I learn that:

1. Branches are nothing but pointers. `main` branch? `bug_fix` branch? `$important_name` branch? Those are pointers to a commit, which is a node in a tree. Additional commits move the pointer along. At the same time, we can forcibly move the branch pointer to a different start point using `git branch -f `. Branches are like, just an idea.

2. `origin/main` is a remote branch that tracks `main` on the remote. The remote branch is stored locally: your `main` branch is compared with `origin/main` to figure out where new commits (either on remote or local) will go. We can even set `origin/main` to track a local branch that is named something else, like `foo` using `git branch -u`

3. merge and rebase: Merging creates a commit with two parents. This makes sense when merging with pull requests / new feature branches. This can be messy for navigating histories. Rebasing changes the start point for the branching commits e.g. if branch `main` is updated and we want those commits in our `dev` branch, we use a rebase to bring them over. In general. rebase lets us move commits around.

4. pull = fetch + merge. Even better, you can have a cleaner history if you `git pull --rebase`

5. It's all easier with tree view. Seriously. If you have a mental model that looks like this:

this will clearly beat whatever spaghetti you can see with git bash.

- which is probably why VS Code has a nice git tree and I should be using that. That's all for today. Happy surviving.



Monday, 27 May 2024

The briefest possible summary of The Anxious Generation by Jonathan Haidt

Interestingly, both Jonathan Haidt and Scott Galloway are faculty at the NYU Stern School of Business, and I've read both their books recently. I signed up for a book club (!) that was going to discuss The Anxious Generation and I've recently finished the book. A few thoughts:

We live in a world that allowed this to happen: In a world that made gas chambers, leaded petrol, chlorofluorocarbons, and uncontrollable amounts of climate change, perhaps it fits the pattern to have a few technology behemoths take control over the minds (via the attention) of not only an entire generation, but also much of communicable culture. It is also ironic that these technologies steal precisely the attention that would allow someone to realise these technologies' harms by disguising them as pleasure. 

It's not too late: Haidt strategically pushes to introduce four behavioural norms that solve collective action problems - namely, if my child doesn't have Instagram while everyone else in their class does, my child will be the outcast. Alternatively, if my social media company doesn't target 10-year olds, then this other company will and I'll lose out. These norms are: (1) no smartphones before high schools, (2) no social media before 16, (3) phone-free schools, (4) more independence, play and responsibility in the real world. All of these sound wonderful. I think we should have these norms for a start. Parents and school teachers are already worried about these things, which will help grassroot implementations of these norms.

Everyone needs a life outside - or, you should touch grass: Digital Minimalism by Cal Newport was presumably written for working adults - people who didn't grow up in the Anxious Generation. I'm someone who very much had my adolescent years immersed in social media. All I can say is: I think my life growing up would have been a lot better if everyone played with each other and went outdoors a lot more. I wasn't personally obsessed with technology use, but it was present insofar as it appeared to provide a social life that wasn't readily available in school. For a while, I've been trying to reconfigure my life to get those needs met, and I'm curious what new experiences I'll have.

This is an interesting and important book. Even though the story sounds old - a new technology is bad for people - we must recognise that there is a difference not in degree, but in kind. No previous technological development has had the same capability to assault our attention and dopamine circuits as much as smartphones coupled with social media. I'll want to write about this book again with more nuance and detail, but that's for a subsequent day. Until then, happy surviving.


Sunday, 26 May 2024

Fooled by the Winners - David Lockwood

Nassim Taleb's book 'Fooled by Randomness' tackles epistemological questions. What do we know, and what do we not know? This is interested in questions like survivor bias, black swan events, and how random noise is subject to human interpretation and given meaning (see: much of business news, possibly journalism, history, finance, academic publishing involving statistics). 

David Lockwood writes a similarly fascinating book, 'Fooled by the Winners' (Winners), which is singularly focused on the question of survivor bias. The cover of the book features a WW2 airplane, engulfed in smoke and falling from the sky, bringing this lovely image to mind:


For a process that generates survivors and non-survivors, we obtain information from survivors without hearing from the non-survivors, which is discussed in Part I of Winners. This discusses survivor bias in anti-aircraft fire, hedge funds returns, the results of academic publishing that hit a threshold for statistical significance, medical trials, and start ups. 

Part II of Winners is concerned with a slightly bigger questions. What happens when we (the knower) are part of the survivor group without direct knowledge of non-survivors? This delves into bigger existential questions, pertaining to whether life is likely to continue on Earth, and Fermi's Paradox, which has to do with our non-observation of extra-terrestrial life. Part II tackles the nuclear crisis, and the bizarre strokes of luck that allowed civilisation to not evaporate in smoke - that we are able to write about this now is precisely survivor bias. 

It is also interested in the question of climate change - that we've managed to alter the climate so much without catastrophe yet is by no means suggestive that we can continue to do so. If a catastrophe did happen, we wouldn't be here to write about it. Past behaviour does not imply future behaviour, and chances are that it might happen anyway. Bummer. 

I enjoyed this book - it was right up my alley, and it was well written with great links between chapters. I have a specific complaint about academia (relating to survivor bias) that I will write about some other time. Until then, happy surviving.

Wednesday, 22 May 2024

A weird mistake I made a while back

Back when I was working in a seismology lab, I was told to write my own gridsearch procedure as a pedagogical exercise. For context, each physical station receives a seismic signal at timestamp t. However, we don't know how far away the earthquake is, along with the travel time.

To figure that out, we look at the P and S wave arrival times (example): since these two waves travel at different speeds, we can guess what the speed difference is, and hence guess the travel time. 



Given 3 travel times, a guess at the difference between P and S waves, and the strong assumption that earthquakes cannot happen in the sky, we can locate the event center (hypocenter) and its event time. The guess doesn't have to be super accurate - the locations are improved iteratively.

To write a gridsearch program, I computed the theoretical timing misfit for all boxes in a large volume. I made the mistake of assuming Cartesian coordinates instead of using distance calculations for spheres (weird, I know). Subsequently, I obtained misfit contours that looked a little off.



Given that RMS error (the misfit value) is a smooth convex function of distance, it was weird that some circles would look like they have extra error. 

The reason had to do with floating point division and the difference between `round` and `int` - a postdoc in my group figured this out by looking at my data files that were used to interpolate between pre-computed travel times - some of the travel times were blank (default 0).

 



This was not my finest moment. This meant that for my travel time computations, I had some entries which weren't filled, messing up the interpolation, and giving odd looking contours in the colourmap above. 

The first lesson was to perhaps pay attention to how floats are cast. The second lesson was about the importance of code review, which was a mostly alien concept to me. It has to do with the group culture, perhaps - the way they deal with technical debt and operational efficacy.

Tuesday, 21 May 2024

Digital Minimalism by Cal Newport

I first heard about Cal Newport through an episode of 10% Happier that discussed his latest book, Slow Productivity. I might read more of that later next month. I chanced upon Newport's earlier book, Digital Minimalism, published in 2019. I thought I had a good grasp on the hows and whys of approaching technology use, but I turned out to be wrong. A few pointers I picked up:

It's designed this way: Snapchat, LinkedIn, and Instagram were founded by students of a Stanford psychology class. Human brains are easy to manipulate to begin with (cognitive biases). Stack that on top of screens that connect you to a virtual reality and slot machine-style design: pulling down to refresh, pops, little red notification lights, unpredictable "social interactions" - dopamine hit after dopamine hit. 

That being said, it's not that useful to see tech use as an addiction. At worst (or best, if you are in the business of making these things), tech use is a medium-intensity addiction - getting off Instagram probably won't give you physical withdrawals that a smoker or workaholic might get (I'm now imagining a fidgety 9-year old who cannot get their hands off their phone). Rather, Newport takes pains to point out that mitigating the harms of technology use depends on how you use it, without doubling down on the banal perspective of "it just depends". To that end, the book asks us to think intentionally about what we use and how we use it.

Use technology with intention: A digital detox asks us to get away from our phones for say, a month. This is the abstention perspective - we experience a hole in our lives during that month, and we resume using our phones after that month. 

Let's suppose instead that we think carefully about what we use our phone for, and what sort of needs that it might meet. We will then want to ask how we can meet those same needs without using our phones all that much. For instance, perhaps we value social connection with our friends - we want to stay updated on what they're doing. Instead of scrolling through their Instagram Stories, we could schedule a time to meet them in person to catch up - the skin and bone encounter is way more valuable.

By thinking about what we get out of using technology and the needs that it meet, we can see how they fit into our lives. This gives us the space to think about our needs, and to use technology in more limited and specific ways to meet our needs.

Build a life worth living: It's probably no coincidence that the decline of organised community and public life (see: Bowling Alone) facilitates a shift towards the "connection" over the "conversation" - the vague feeling of having been social, without taking on the risk and interaction. There is a void in our lives that social media use fills (as a major subset of technology use). 

The book asks us to do things with our hands and get in touch with the real world, and gives metalworking, taking walks, and playing the guitar as examples. That's pretty male-coded; I could see crochet, cooking, and doing the housework as examples of doing things with your hands too.

The book also asks us to take part in structured social activities. While we don't necessarily have to go to church, we can join communities (CrossFit, board gaming, book clubs), or even make them ourselves (giving the example of Ben Franklin, though meetup.com would be a pretty good example today). By giving ourselves the opportunities for thick social interactions where we have to read complex social cues, we exercise the social part of our brain, which happens to be our default brain. This meets the need that social media initially promised to fill, and hence sets us free from its grasp.

This tackles the heart of the problem - we are social beings that need a social life. While we could duct tape over some of it with social media, it doesn't really plug the whole. We can't confront and reduce technology use if we don't think of way to meet our own needs. 

This is an interesting book, and offers many suggestions that can be put into practice. I'll try some of them (quarterly and weekly plans, dumbphone, structured social activities, crafts, walks) and see how it goes.

Monday, 20 May 2024

Monkeys, slot machines, and mindfulness

A story I heard from Radiolab: William Schultz et al. (1993) gives juice to monkeys, and learns that the dopamine in monkey brains are initially coincidental with the juice giving. Over time, the dopamine spike shifts earlier and earlier in response to cues that come before the juice giving - when the room light turns on, or when the researchers' footsteps are audible in the hallway.

My reading of this story: as animals, humans too, are wired to anticipate rewards. Dopamine is not simply a reward chemical, but primes us (our monkey brains) for nice rewards (juice). We daydream about success - a mate, the admiration of our peers, lunch, or having croissants - way before any of those happen. We are wired to think about the future, and it is real work to live in the present (mindfulness).

The second idea: reward variability feels amazing. When we pull a slot machine, we anticipate a reward that is variable, since slot machines are programmed to have negative expectation value, while appearing to give random outcomes. When the numbers land on a special combination, the lights and sounds go off, and coins start to trickle out from the machine (I think? I've not played slots before). 

It turns out that our brain really loves variable rewards - we want to figure out the pattern behind them so that we can get more of the reward (a mate, admiration of our peers, lunch, or having croissants). This is also the basis of addiction - we have an irresistible itch (anticipation) for an action (say, pulling a slot machine, checking your phone, playing a video game) that gives rewards (money, social standing, croissants).

All this to say that we really are so many monkeys chasing so many rewards in our careers, schools, online forums, and video games. Some are more useful than others - some of these even help you pay the bills. What I would like to reflect on is our wonderful capability to be so caught up in this world - this is a nice angle to start thinking about mindfulness and being in the present. 

As creatures of anticipation, we receive our object (juice), and start to anticipate the next reward. The point is to sit down and drink the juice - this is not a call to enter a stupor of self-reflexivity and not achieve anything in your life. Rather, it is an invitation (to myself, mostly) to sit back and think critically about what drives us, what gives us meaning, and what orientates and moves us as we exist in this world. 

Dan Harris, in his book 10% Happier, relates the story of a meditation teacher who tells his students to be simple. The narrator then observes the teacher screaming red-faced at a biscuit seller who the teacher believes to be overcharging him. When asked, the teacher says: be simple, not a simpleton.  

The point is to be simple. Achievement, focus, and success are alright. They are desirable. I should apply ourselves to what I do. At the same time, there must be a way to be less caught up with the whims of the world - to experience the present moment more clearly, and to act wisely. To be simple, but not a simpleton. 

Sunday, 19 May 2024

A sketch of topics I'd cover in a graduation speech

I haven't had quite enough opportunities to be self-aggrandising in front of large crowds. In preparation for a hypothetical session at the podium, I'd give the following advice, informed by a few books I've read (How to Fail at almost everything by Scott Adams, Algebra of Wealth by Scott Galloway, Fooled by Randomness by Nassim Taleb).

Passion sucks because of survivorship bias: passion was never a reason why successful people succeeded. Postdocs are typically passionate - not all of them become a tenured academic. Interns in investment banking are typically passionate - not all of them will obtain a return offer. Most entrepreneurs are passionate - most of them will fail their first few startups too. People who tell us that passion matters are survivors who do not know the non-survivors. Look at the entire population to see what matters.

Figure out your talent, and talk to many people: If passion doesn't matter, we should figure out what we're good at (our talent) by trying many different things. This exposes us to rejection (good practice) and gives us novel information on what we're good at. On that theme, we should talk to many people to ask for guidance on what we'd like to do. I reached out to so many people to talk about graduate school, which was incredibly helpful since all the information I obtained told me to do anything else. There's a fear of rejection associated with talking to new people - we welcome rejection in search of useful connections and conversations.

Protect your attention and energy: we exist as finite and cranky human beings. However, a legion of Silicon Valley tech prophets is hiring psychologists and conducting endless A/B tests to figure out how to hack your attention - emotionally charged and depressing news, infinite updates from people you barely know, and short-form videos supercharged by algorithmic selection. Your attention and energy are the most important things you have, and the only person who can take care of yourself is you - billion-dollar companies are uniquely unsuited for that task. To that end, reduce the clutter in your digital life (Digital Minimalism by Cal Newport). Stay healthy, exercise, and go on walks. Manage the amount of energy you have to live the life you want.

These main beats should be appropriate in an advice-giving setting. That being said, I think there's so much more to talk about for survivorship bias - it represents a sort of anti-knowledge in forcing us to pay attention to what we cannot see and what we cannot know.

Thursday, 16 May 2024

Is masculinity in trouble? It probably depends who you listen to.

Unfortunately, I've been online in the last ten years or so, which means that I've seen my share of discourse on "toxic masculinity" and/or how some men were singularly awful to some people. I find it entirely believable that many people have had unpleasant experiences with male figures in their lives - I'm not exempt from this. That being said, what I find interesting is the following: 

(1) There seems to be a lack of empathy for people existing at the margins - the people who have fallen out of labour market participation, young angry men without economic viability which leads to diminishing prospects for a fulfilling relationship. There's this uncanny link to Gladwell's series on guns - sin is the failure to bother to care. Does being online lead to diminished empathy? Is it a function of late capitalism and declining civic participation? I have no idea.

(2) There seems to be a strong demand for role models. We have lifestyle and productivity vloggers in the vein of "this is how I woke up at 3am everyday and climbed two mountains before breakfast". We also have people like JBP who give the very useful advice of cleaning your room and sorting out your life, along with the whole fitness-masculinity-strength sphere. This is a strong function of having the internet effectively parent a generation.

(3) Seeing constitutes reality, and seeing is no longer a shared act. I find it hard sometimes to wrap my head around the idea that as a result of my regular media consumption I won't find many opinions that differ from mine, and I'm trying to break out of that by reading books I ordinarily wouldn't read.

And most of all, I don't feel like any of the discourse particularly matters much. I do however hope to mentor people when I have the capacity and stability to do so. I have been in teaching / mentor roles over the past few years so I do have some teaching / mentoring instinct, but that was in the context of being a student. I'm curious how it'll be going forward.

PS: My manual on getting out of research is found here.

Wednesday, 15 May 2024

Features of python classes that I learned and forgot about

 I started learning python over ten years ago in an informal setting. The way I've learned seem to have been whatever I saw on StackOverflow and whatever I saw people doing around me. I've not felt like I've had a solid grasp of the more advanced concepts - I appear to have skillfully bumbled along for ten years. After doing some review yesterday, here is a list of things that I must have read and then promptly forgotten at some point:

self: this references the current instance. When this is the first argument in the method, we can access all other instance variables and methods. I've always used this without thinking.

classmethod: the `@classmethod` decorator modifies a function inside a class (or, a method) to take in `cls` as an argument (convention). This lets us define alternative constructors i.e. feed arguments packaged differently into `__init__` in re-usable ways packed with the class e.g. unpacking a tuple. This also accesses class-level data.

staticmethod: the `@staticmethod` decorator modifies the method such that it behaves like a normal function, but is packaged with the class because it is called so often. `self` is not one of its arguments, hence 'normal function'.

getter setter: we use these to protect the class states from outside access. Why I would ever use this is mysterious to me, but setter methods allow you to do internal validation and throw errors if needed.

__len__, __getitem__: When reading Fluent Python they discussed how `len` was like a special unary operator. Default python data-types and numpy objects have their length stored in their C objects and can be retrieved very quickly. On the other hand, `getitem` allows us to use the `[]` square brackets to index our class, which can be very powerful - we can access the class objects like a list, allowing us to iterate and slice.

Tuesday, 14 May 2024

Nassim Taleb's Black Swan and Scott Adam's Systems

 I noticed a point of intersection between the books The Black Swan and How to Fail at Almost Everything. These two authors share some similarity in their epistemological position. Namely, we learn by doing. We want to give ourselves opportunities to get lucky. 

Specifically, How to Fail advocates for thinking in terms of systems - the things we do need not add up to a concrete something. Rather, we try new ventures - startups, patents, ideas, books, practices, routines - with only the desire to become a better person. While the 'goal' tells us to get a job, the 'system' tells us to become the person who can better get a job. By exposing ourselves to reality and getting feedback, we learn what the world likes and doesn't like. This lets us encounter positive Black Swan events: low probability events with an outsized impact that are not within the confines of what we previously knew.

For instance, if we were to consistently network and reach out to people for chats in exchange for sharing knowledge, we expose ourselves to the low probability event of getting a nice job recommendation. If we don't, perhaps we get some juicy gossip, or minimally a pleasant conversation. If we were a serial entrepreneur, one of those business ventures will strike gold.

If it is true that timing and luck matters so much (think of Gladwell's What the Dog Saw and The Tipping Point), we should let ourselves roll the dice as many times as we possibly can. This is perhaps the 'intellectual' polish on the notion that "luck finds those who are prepared". This "preparation" is not in the sense of "having studied for an exam", but rather "preparation" as having multiple systems that expose yourself to large positive outcomes.

Monday, 13 May 2024

Summary of Week 1 of Statistical Rethinking

I've been making an effort to cover extra reading material in my free time. I thought this course would provide an alternative perspective on statistical thinking, especially not having taken a formal stats course (and also having a deep distrust of hypothesis testing).

I've finally finished the homework for the first week, so here are (I think) the main ideas:

The data comes from somewhere: The data is generated through a process. Perhaps it is drawn from a uniform distribution, and the grad student experimenter has a small chance of writing down the wrong values. Or, perhaps it depends on the measured position of the Moon and Mars, both with experimental error. By using Directed Acyclic Graphs (DAG) we represent our conceptual prior of how variables affect each other to generate the observations.

The tree in the forest: We typically use best-fit points or Maximum Likelihood Estimates to describe the model and to make predictions. Bayesian rethinking tells us that the model parameters have a probability distribution. By using that as a weight and integrating that with the data generating process, we obtain the average of all possible realisations in the posterior predictive distribution.

Prior beliefs are everywhere: The choice of model, or DAG, or initial parameter distribution is a prior that we should state explicitly - it is better to see our assumptions clearly from the get go. The belief that our data follows some distribution in asymptotic limits (if that even exists) is a sort of prior too.

I'm enjoying this course. It stresses the fact that statistical thinking is a golem - a powerful machine that is possibly destructive if misunderstood, and provides tools (new to me) that help to clarify thinking. I'm looking forward to the rest of the lectures.

Sunday, 12 May 2024

Three recommendations for adding systems into your life

The idea of 'systems-over-goals' was discussed in Scott Adam's book, How to Fail at Almost Everything and Still Win Big. Here, I'd like to share three things to keep in mind when fiddling with the way your life works in the pursuit of some broad and significant outcome.

Firstly, do it everyday - if you can. We want to do things automatically as we are creatures of habit. The more ingrained it is into our everyday lives, the less we think about the fact we're doing something we wouldn't ordinarily do, be it working out, playing a new instrument, or reading books from a specific genre. That being said, we don't always have the luxury of a static schedule - we will skip some days, and that's ok. 

Secondly, keep it simple and do less. Changing your life is hard enough, and we want to keep things small lest we run the risk of burning out. This happened to me as I was trying to engineer my life in the beginning of this year - I felt that my to-do list was unbounded in size and I didn't have anything under control. We should do simpler things, and do less. To that end, I'm giving atomic essays a try, and also confining my 'extra-curriculars' to finite time slots on a frequency that is not-everyday. 

Lastly, remember your why. The things you do (or are trying to make yourself do) should fit into a broader story of who you are and who you're trying to be - it is easier to do things when they fit into your identity and your vision of who you really are. 

Systems beat goals every time. However, we should be careful to not beat our schedules into the dirt. These recommendations will help counterbalance the instinct to over-engineer your life.