Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

Sunday, 10 January 2021

New republics


There was a time when libertarians fantasized about starting their own countries on floating platforms. Now anyone can do it from home, on a digital platform. Some of these new countries are quite big. Facebook now has 1.7 billion users, more citizens (if you want to look at it that way) than China, and more adherents than Catholicism. 

If you're thinking that websites like this are just games ('Twitter isn't real life' etc.), you'd be right. But games are a serious business. Game designer Reed Berkowitz recently explored how QAnon (whose shaman is pictured) might have grown out of the same sorts of incentives that are generated by live-action role-playing and alternate reality games. People are given a quest (Who is Q?) and the motivation to want to complete it (this will show you the way thing really are). They build a world around them without a graphics card in sight.

This may sound like a new idea, or at least an eccentric one, but it's actually a highly familiar one in political science and economics, at least in the branch of economics known as the New Institutional Economics (NIE). The Nobellist Douglass North defined institutions as 'the rules of the game' in a given society. He may have meant it as a metaphor, but there's no reason why the rules of the game can't be the rules of a literal game.

Or, say, the ways a website is set up - its terms of service, its modalities, its incentive structures. The differences between social media sites might seem like just a matter of choosing different products - Twitter allows you less space per message; this bus company lets you drink coffee onboard. But there's more going on. The different sites have a vibe, a style, even (by now) a history - and we act differently when we're on (or in) them.

That's partly because of the multiplication of incentives within these worlds. I saw a link to Berkowitz's piece on Justin Murphy's Twitter feed. Murphy left academia, as he says, 'to spend more time on research and teaching,' and he seems increasingly interested in online learning not just a site for educational content, but for educational incentives. That last thing was what MOOCs were lacking. Murphy will send you an email a day (if you want him to) to help you learn R (What is R?). Khan Academy and other sites give you points, badges, etc. so that you keep levelling up in the game of Knowledge.

Meanwhile, in the world of real games (whatever that means), video games are apparently getting longer and increasingly nesting 'micro-transactions' within them to get you to pay up for a snazzier helmet, a deadlier weapon, or a more interesting adventure. (From what I can tell, this is one of the complainers' main complaints about the beautiful Assassin's Creed Odyssey.) We're long past the point at which companies have started selling real-world products in digital universes like Second Life (in fact, that's apparently something Reed Berkowitz used to do for a living). We're surely not far from Borgesian 'games' that electro-shock your brain into suffering or ecstasy as you proceed bravely through their new world.

But we're off on a side-quest now, so let's go back to something I wrote before. The different social media sites that already exist, I said, 'have a vibe, a style, even (by now) a history - and we act differently when we're on (or in) them.' If this reminds you of countries, well, that was sort of the point. Diving into an online community is kind of like visiting a foreign country and immersing itself into its exotic ways, its alien norms.

The reason countries used to be so different was because they had different pasts that led to different institutions, norms, customs - a different cultural infrastructure that in turn helped shape the way people were. I'm old enough to remember a time when people would talk openly about the way different countries (and its inhabitants) were, and even if some of this was ignorant or over-confident, some of it seemed about right. It had to be, in a sense - if changing laws or customs has any power to change behaviours, countries with different laws and customs should have a different vibe.

Of course, they still do, to a great extent, and this should remind us of something. The kinds of incentive structures nations have built up over the centuries are pretty formidable, and some of the axes they wield (like laws) ultimately trump the structures set up by social media companies. Twitter can oust Trump from its platform, true, but Twitter still ultimately exists at the pleasure of the US and other governments. Nation-states aren't going away any time soon, and their age-old institutions and norms continue to shape us in profound ways.

Still, sites like the United States of America are starting to seem a bit last century. If it's incentives and information that shape people, especially as they move like questers through whatever spaces open before them, trying to make meaning out of their lives - if that's what is forming individuals and communities, Arizona and Invercargill are really no match for the world wide web. What we'll have - what we to some extent already have - will be new republics shaped online, with new compatriots that are as different, and sometimes as hostile, to each other as Spaniards and Swedes were in 1634. 

The only difference is that this time, the citizens of these new republics - dressed differently, speaking different and mutually unintelligible languages, worshiping different gods - won't be separated by channels or ranges, but will be living side-by-side. And when fighting breaks out, as it has already started to, old-timers speaking of 'internal' or 'civil' war won't seem alarmist, but just quaint. 








Friday, 19 June 2020

Beta's colander


Buy SWHF Stainless Steel 5 L Jumbo Colander and Strainer Online at ...
This is a classic titanic post, because (as so often) I don't really know what I'm talking about. Through the lockdown I made a half-hearted attempt to learn R, the leading statistical programme. As usual, what caught my eye was an ancient Greek. 

Specifically, Eratosthenes of Cyrene. Eratosthenes is one of the great figures of Hellenistic Alexandria. He was head of the library there, the highest intellectual position of the day. He's best remembered today for estimating the circumference of the earth to an astounding degree of accuracy, but he was also a polymath interested in literature, music, and, as we'll see, mathematics. He was called 'Beta' by his peers, not because he was on Reddit, but because he was the second best at everything.

Not too far into my studies in R, I came across Eratosthenes' sieve, a simple algorithm that's often used as an exercise for coding students. What follows is an attempt to unpack one way of coding Eratosthenes' sieve in R, with some help from a friend and some code I found online. I struggled with it a bit myself, which should hopefully put me in the ideal position to explain, since I can remember what confused me (everything), and nothing about it seems obvious to me. 

I'll start with the sieve itself. The point of it is to find all the prime numbers up to a certain point (let's say, up to 100). Starting with 2, what you do is to move through the rest of the numbers crossing out all of the multiples of 2 (since if they're multiples of any other number higher than 1 they can't be prime). Then you do the same with 3, 4, and so on, until you can't do it anymore, since all the multiples of the number you started with have already been crossed out (as multiples of an earlier number). Then you can look at all the numbers that haven't been crossed out. Those are your primes. 




I guess it makes sense as an exercise for beginner coders because it's a pretty easy to understand algorithm, a set of steps for a brain or computer to work through to get a set of outputs (here, prime numbers).


So - as previously advertized - below is one way of getting the R programme to become, for a thrilling and infinitely repeatable moment, the head librarian of Alexandria. After the code itself I'll break it all up into bits, accompanying each bit with some comments that hopefully a) are correct and b) help you understand what's going on. Code is bold, the commentary (a highly Alexandrian form) not. The commentary is talking to R and telling it what to do (imperative mood).



sieve <- function(n) {   
if (n < 2) return(NULL) 
  a <- rep(T, n) 
  a[1] <- F 
  for(i in seq(n)) { 
    if (a[i]) { 
      j <- i * i 
      if (j > n) return(which(a)) 
      a[seq(j, n, by=i)] <- F 

   }
  }
}

sieve <- function(n) { 
Make "sieve" a function that does the below to a number we'll call "n." (This just names our algorithm and makes it a function, a way of doing things to what's in the brackets that follow).

if (n < 2) return(NULL) 
a <- rep(T, n) 

If n is smaller than 2 then spit out NULL. (In other words, refuse to do this computation if it's on a number of numbers less than 2).

Make a vector called "a" and store in it n repetitions, all marked "true." (T stands for 'true.' This is like writing out the number in the grid above. Saying they're all true effectively means we're starting with the assumption that they're all prime.)

a[1] <- F 
Store the first item as false in "a." (Because we want to get rid of 1 immediately?)

for(i in seq(n)) { 
Start with i = 1, iterating the code between here and the closing }, incrementing by one each time, until i = seq(n). (Note the opening curly bracket. The code within the for loop, contained between the curly brackets, will run a number of times equal to the number of elements in seq(n), starting with i = 1, and with the value of i increasing by one each time it runs.)

if (a[i]) { 
If a[i] is true, the code within the ensuing curly brackets will execute. If a[i] is false, it won't. (So if an individual number is false, it won't run the code. At this point that's just 1, as specified above, so I think this just stops R running this algorithm with the number 1. That's actually important, because if it did it would cross off all the numbers and we wouldn't get any primes; another way of looking at this is that being a multiple of 1 doesn't mean a number isn't a prime, and the algorithm needs to recognize this.)

j <- i * I
This finds the square of i and stores it in variable j. Remember we're in the for loop, with incrementing each time the loop repeats. The first time round i = 1 and j = 1; the second, i = 2 and j = 4; the third, i = 3 and j = 9; and so on.

 if (j > n) 
If (and only if) the square of i is greater than the number of elements in the entire sequence...(i.e. that number times itself is larger than e.g. 100...)

return(which(a)) 
Return the sequential positions of all those numbers in a which are true (T). (The idea here is that if we've reach a number whose square is greater then the number of numbers in the sequence, e.g. 100, then we've found all the primes already. I guess this is just a separate assumption that happens to be true?)

a[seq(j, n, by=i)] <- F 
Mark as F (false, i.e. not prime - in other words, cross out) all the numbers in a between the jth and nth (the nth being the last) that are divisible by (that's what 'by' does) i (and thus aren't prime). This line is the heart and soul of the code, the steely essence of Beta's colander. 

OK, I'm still not sure I understand all of that, so if you want to try to help out in the comments be my guest.