From J Wiki
Jump to navigation Jump to search
   There is something uncanny about the power of a happily chosen ideographic language; for it often allows one to express relations which have no names in natural language and therefore have never been noticed by anyone.  Symbolism, then, becomes an organ of discovery rather than mere notation.
      - Susan K. Langer, 1967

Beginner's regatta

Here we examine how to fool a Windows PC into thinking you are at the keyboard when you do not want the screensaver to invoke itself.

Staying Awake

Suppose you have a Windows machine for which you do not have admin privileges and which is locked-down to prevent registry changes. Further suppose that you wish to keep the machine from going into “sleep” mode which it will do after 15 minutes.

There are a number of pieces of code and advice you can find on the Web with names like Insomnia, Caffeine, and Noise. Like many things on the Web, these often do not work as advertised depending on the set-up and version of Windows you are running. I tried a few but none of them did what I wanted, so I wrote my own in J.

The screensaver I like is the “Photos” one which will run a slideshow of pictures in a given directory (and the directories contained by the chosen one.) This is invoked by the “PhotoScreensaver.scr” executable found under \Windows\system32. You can right-click on this to “Test” or “Configure” it. The configuration options are the directory from which you want to start displaying pictures, which of three speeds pictures should be changed, and whether to shuffle to pictures (or play them in alphabetical order as found in the directory.)

Once you have set these options manually – I have not yet found a way to set them programmatically without access to the registry – you can invoke this screensaver from a command line with the “/s” option, so “PhotoScreensaver.scr /s” will run the screensaver with the settings chosen.

So, these two lines, each one run in a separate J session, are enough to keep the OS from going into sleep mode.

The first invokes the screensaver every 30 seconds; however, since the invocation blocks execution, only the first instance will ever be run by this line alone:

3 : 'while. 1 do. wait 30 [shell ''PhotoScreensaver.scr /s & cd C:/Windows/System32'' end.']''

To get around this, we run this other line in another session:

3 : 'while. 1 do. wait 800 [shell ''pskill PhotoScreensaver'' end.']''

This endless loop uses the system utility “pskill” to kill the screensaver at intervals less than the time-out interval which is 900 seconds in this case.

One other wrinkle is that the slideshow always begins with the same first picture even in “shuffle” mode. The picture it starts with is always the first on in alphabetical order at the root of the directory chosen. If this is too boring, we can run a third J session to change the first picture every so many seconds like this:

3 : 'while. 1 do. wait 290 [ change1Pic '' end.']''

This example defaults to a hard-coded starting directory but the verb is designed to allow an argument to override this location. More importantly, this depends on the existence of the variables created by a process that reads all the file information on a disk and stores the results in six vectors:

  1. FLNMS: a vector of all filenames on the disk, duplicates included.
  2. FLDTS: a vector corresponding to the first with all the save dates and times.
  3. FLSZS: a vector corresponding to the first with all the file sizes in bytes.
  4. FLPARENT: a vector corresponding to the first with the index into the following list of directories of the parent directory of each file.
  5. DIRNMS: a vector of the full path names for each directory on the disk (not the same length as FLNMS like the previous ones.)
  6. DIRDEP: a vector of integers indexing the above vector to explicitly denote the parent/child relationship of each directory and its sub-directories.

Only the variables numbered 1, 4, and 5 are used in this example as they are all that is necessary:

NB.* change1stPic.ijs: change first picture file regularly.

require 'WS'
require '~Code/math.ijs'  NB. For "setSeed".


flsuff=: ] }.~ [: >: '.' i:~ ]  NB. Return file name suffix after the final ".".

setSeed ''    NB. Pick different starting random seed with each invocation.

change1Pic=: 3 : 0
   topPicDir=. 'C:/amisc/pix'
   if. 0~:#y do. topPicDir=. y end.
   suffs=. (tolower&.>flsuff&.>FLNMS) e. 'jpg';'png';'gif'
   whpix=. I. (FLPARENT e. I. (12{.&.>DIRNMS) = <topPicDir) *. suffs
   pick1=. whpix{~?#whpix   NB. Pick random (index of) picture.
   pic=. (;DIRNMS{~pick1{FLPARENT),'/',;pick1{FLNMS
   NB. File name "__.*" will be 1st alphabetically.
   shell 'del /Q ',topPicDir,'\__.*'
   cmd=. 'copy /y "',(pic,'" ',topPicDir,'/__.',flsuff pic) rplc '/\'
   smoutput (":qts''),': ',;pick1{FLNMS [ shell cmd

3 : 0 ] 300   NB. Every 300 seconds
   while. 1 do. wait y [ change1Pic '' end.

The first two lines read some utility code. The third line reads the afore-mentioned variables from file. The next two are self-explanatory.

The main routine "change1Pic" takes either the default directory or the one specified at invocation, selects the location of all the files with picture suffixes that we care about, selects one at random, and copies it to the name beginning with double underscore as this is likely to be the first name alphabetically.

Show and Tell

We look at a presentation recently given by the Chief Experience Officer of Dyadic Systems, Morten Kromberg, on how the language APL is doing better at working with existing tools than has formerly been the case.

The State of APL 2019

The CXO of Dyalog APL recently came to New York for some presentations on new features of their product. He started with the “toy” problem of generating an “involuted” matrix.

Involution explained.jpg

He then proceeded to show us how this APL code works well with Microsoft’s Visual Studio, a standard programming environment for many people.

Involution in Visual Studio-50p.jpg

Morten then followed up with examples of how the same APL code can run on many different platforms.

Dyalog APL on Multiple Platforms 50p.jpg

He then expanded the simple “command line” version of the involution code to demonstrate a version with a GUI.

InvoluteUI code 50p.jpg

He then delved into some of the underpinnings of some of the techniques for achieving this seamless multi-platform ability: here we see him showing how an APL “JSONServer” uses the widely-used JSON format for representing data, including arrays. Unfortunately and unsurprisingly, JSON does not handle arrays greater than 1-dimension so all APL arrays have to be flattened in this fashion.

JSONServer in Dyalog APL 50p.jpg

Here we see some details of using the JSONServer from within an interactive APL session:

Example of using JSONServer 50p.jpg

Next, Morten briefly introduced the idea of Docker containers which are encapsulated virtual machines that can be deployed for applications under specific operating systems but able to run across different physical platforms.  He then showed us some of the variety of publicly-available Docker images with Dyalog APL on different platforms.

Public Dyalog containers 50p.jpg

He introduced a new licensing scheme for Dyalog to make it freely available as a public container.

New Linux license for Dyalog 50p.jpg

Morten was followed by Paul Mansour who runs a company that uses Dyalog APL to deliver sophisticated financial tools for working with fixed-income securities. Paul demonstrated how he uses the version control system “Git” to track and maintain different versions of his APL code.

Paul demoing git 50p.jpg

Paul showed us a tool he has developed to implement “a radically simplified Git branching model and workflow designed for small teams of APL programmers” based on the “OneFlow” Git model developed by Adam Ruka.

AcreFlow introduction 50p.jpg

This is a simplified workflow for using Git in such a way that the most current release of the code is always in a good state to be deployed. The simplicity of this workflow sacrifices the ability to percolate fixes to older version into more recent ones – these changes would have to be done manually – but it does this to concentrate on keeping the most recent release in a state of constant readiness.

Paul suggested that the natural unit for APL in version control is the individual function. This is different from my own preference with J under Git where I work with logically-related collections of functions.

All in all, the two presenters made good arguments for the ability of Dyalog APL to work and play well with coding tools and environments that are mainstream as opposed the APL’s history of being in its own “walled garden.”

Advanced Topics

We look at a column on Medium about some serious problems that the social media platform Facebook has caused for human communication. Also, we consider how to create higher-order functions in R - a language which lacks the vocabulary that J has for distinguishing between different kinds of higher-order functions.

How Facebook Has Flattened Human Communication

Online services demand easily classified content. Users have obliged.

by David Auerbach / Aug 28, 2018

   “Since you are tongue-tied and so loath to speak, 
    In dumb significants proclaim your thoughts.”
     — Shakespeare, Henry VI, Part 1
   “I feel so bad for the millennials. God, they just had their universe handed to them in hashtags.”
    — Ottessa Moshfegh

The primitive level of user feedback encouraged by online services is a feature, not a bug. It is vastly easier for a computer to make sense out of a “like” or a “⭐⭐⭐⭐⭐” than to parse meaning out of raw text. Yelp’s user reviews are a necessary part of their appeal to restaurant-goers, but Yelp could not exist without the star ratings, which allow for convenient sorting, filtering, and historical analysis over time (for instance, to track whether a restaurant is getting worse). This leads to what I’ll term…

The First Law of Internet Data

In any computational context, explicitly structured data floats to the top.

“Explicitly structured” data is any data that brings with it categories, quantification, and/or rankings. This data is self-contained, not requiring any greater context to be put to use. Data that exists in a structured and quantifiable context—be it the DSM, credit records, Dungeons & Dragons, financial transactions, Amazon product categories, or Facebook profiles — will become more useful and more important to algorithms, and to the people and companies using those algorithms, than unstructured data like text in human language, images, and video.

This law was obscured in the early days of the internet because there was so little explicitly quantified data. Explicitly quantified metadata, like the link graph, which Google exploited so lucratively, underscored that algorithms gravitate toward explicitly quantified data. In other words, the early days of the internet were an aberration. In retrospect, the early internet was the unrepresentative beginning of a process of explicit quantification that has since taken off with the advent of social media platforms like Facebook, Snapchat, Instagram, and Twitter, which are all part of the new norm. This also includes Amazon, eBay, and other companies dealing in explicitly quantified data.

Web 2.0 was not about social per se. Rather, it was about the classification of the social, and more generally the classification of life. Google had vacuumed up all that could be vacuumed out of the unstructured data. The maturation of the web demanded more explicitly organized content that could more easily be analyzed by computers. And the best way to do this at scale was to employ users to create that data.

Explicitly quantified data requires that data be labeled and classified before it can be sorted and ordered. The project of archives like the Library of Congress isn’t sorting the books per se; it’s developing the overarching classification that determines what order the books should be in. No classification, no sorting. Even machine learning fares worse when “unsupervised”—that is, when it is not provided with a preexisting classificatory framework.

The Second Law of Internet Data

For any data set, the classification is more important than what’s being classified.

The conclusions and impact of data analyses more often flow from the classifications under which the data has been gathered than from the data itself. When Facebook groups people together in some category like “beer drinkers” or “fashion enthusiasts,” there isn’t some essential trait to what unifies the people in that group. Like Google’s secret recipe, Facebook’s classification has no actual secret to it. It is just an amalgam of all the individual factors that, when summed, happened to trip the category detector. Whatever it was that caused Facebook to decide I had an African-American “ethnic affinity” (was it my Sun Ra records?), it’s not anything that would clearly cause a human to decide that I have such an affinity.

What’s important, instead, is that such a category exists, because it dictates how I will be treated in the future. The name of the category—whether “African American,” “ethnic minority,” “African descent,” or “black”—is more important than the criteria for the category. Facebook’s learned criteria for these categories would significantly overlap, yet the ultimate classification possesses a distinctly different meaning in each case. But the distinction between criteria is obscured. We never see the criteria, and very frequently this criteria is arbitrary or flat-out wrong. The choice of classification is more important than how the classification is performed.

Written comments on an article don’t give Facebook a lot to go on; it’s too difficult to derive sentiment from the ambiguities of written text.

Here, Facebook and other computational classifiers exacerbate the existing problems of provisional taxonomies. The categories of the DSM dictated more about how a patient population was seen than the underlying characteristics of each individual, because it was the category tallies that made it into the data syntheses. One’s picture of the economy depends more on how unemployment is defined (whether it includes people who’ve stopped looking for a job, part-time workers, temporary workers, etc.) than it does on the raw experiences and opinions of citizens. And your opinion of your own health depends more on whether your weight, diet, and lifestyle are classified into “healthy” or “unhealthy” buckets than it does on the raw statistics themselves. Even the name of a category—“fat” versus “overweight” versus “obese”—carries with it associations that condition how the classification is interpreted.

Some classifications are far more successful and popular than others. The dominant rule of thumb is…

The Third Law of Internet Data

Simpler classifications will tend to defeat more elaborate classifications.

The simplicity of feedback mechanisms (likes, star ratings, etc.) is intentional. Internet services can deal with complicated ontologies when they need to, but business and technical inertia privilege simpler ones. Facebook waited 10 years to add reactions beyond “like” and long resisted the calls for a “dislike” button, forcing their users to like death announcements and political scandals. Facebook preferred a simple bimodal interested/uninterested metric. When Facebook finally decided to appease its users, it added five sentiments to the original like: love, haha, wow, sad, and angry. It is no coincidence that the two negative sentiments are at the end: “sad” and “angry” are more ambiguous than the others. If I express a positive reaction to something, I’m definitely interested in it. If I’m made sad or angry by something, I may still be interested in it, or perhaps I want to avoid it. Those reactions are less useful to Facebook.

Facebook’s six reactions are similar to emoji, in that they allow users to express emotion nonverbally, but they are more useful to Facebook because they comprise a simpler classification than the thousands of emoji. BuzzFeedemploys a similar, slightly hipper scheme for the reactions it permits users to post to articles. BuzzFeed’s scheme is tailor-made for market research: content can be surprising, adorable, shocking, funny, etc.

Bloomberg’s Sarah Frier explained how Facebook formulated its new reactions:

Facebook researchers started the project by compiling the most frequent responses people had to posts: “haha,” “LOL,” and “omg so funny” all went in the laughter category, for instance…Then they boiled those categories into six common responses, which Facebook calls Reactions: angry, sad, wow, haha, yay, and love…Yay was ultimately rejected because “it was not universally understood,” says a Facebook spokesperson.

These primitive sentiments, ironically, enable more sophisticated analyses than a more complicated schema would allow—an important reason why simpler classifications tend to defeat more elaborate classifications. Written comments on an article don’t give Facebook a lot to go on; it’s too difficult to derive sentiment from the ambiguities of written text unless the text is as simple as “LOL” or “great.” But a sixfold classification has multiple advantages. Facebook, BuzzFeed, and their kin seek universal and unambiguous sentiments. There is little to no variation in reaction choices across different countries, languages, and cultures.

The sentiments also make it easy to compare posts quantitatively. Users themselves sort articles into “funny,” “happy,” “sad,” “heartwarming,” and “infuriating.” From looking at textual responses, it would be difficult to gauge that “Canada stalls on trade pact” and “pop singer walks off stage” have anything in common, but if they both infuriate users enough to click the “angry” icon, Facebook can detect a commonality. Those classifications permit Facebook to match users’ sentiments with similarly classified articles or try to cheer them up if they’re sad or angry. If reactions to an article are split, Facebook can build subcategories like “funny-heartwarming” and “heartwarming-surprising.” It can track which users react more with anger or laughter and then predict what kinds of content they’ll tend to respond to in the future. Facebook can isolate particularly grumpy people and reduce their exposure to other users so they don’t drag down the Facebook population. And Facebook trains algorithms to make guesses about articles that don’t yet have reactions. Most significantly, even though these particular six reactions are not a default and universal set, Facebook’s choices will reinforce them as a default set, making them more universal through a feedback loop. The more we classify our reactions by that set of six, the more we’ll be conditioned to gauge our emotions in those terms.

The default six smooth out the variations that were observed when Facebook was conducting tests with a far larger set of emotions, all designed by Disney-Pixar’s Matt Jones. The full list included everything from admiration and affirmation to anger, rage, and terror. A simple classification won out. It is both easier to use and more universal—at the expense of cultural and personal variation. Also, to hear researcher Dacher Keltner tell it to Radiolab’s Andrew Zolli, at the expense of happiness: Countries that expressed the most “happiness” were not actually the happiest in real life. Instead, it was the countries that used the widest array of stickers that did better on various measures of societal health, well-being—even longevity. “It’s not about being the happiest,” Keltner told me, “it’s about being the most emotionally diverse.”

If the restricted set of six reactions has the effect of narrowing emotional diversity, social media and advertising companies view this tradeoff as the necessary cost of gathering better data on users. The restricted emotional language employed by Facebook is a language a computer can understand manipulate at scale. The simplified language of a core set of emotional reactions bridges the computational-human gap—more successfully than the overcomplicated ad hoc classifications of the DSM did.

Instead, these reaction sets are reminiscent of the simpler folk taxonomies of Myers-Briggs, OCEAN, and HEXACO, which also break down complex phenomena into a handful of axes. Facebook’s reactions even approximately map to the Big Five:

Like: Agreeableness
Love: Extroversion
Wow: Openness
Sad: Neuroticism
Angry: Conscientiousness

The odd one out is “haha,” because, as always, laughter eludes easy classification despite being the most universal and nonnegotiable of expressions. Yet for the remaining five, there is an inevitable flattening of cultural differences. Despite Facebook’s empirical research to generalize its six, it’s unlikely that the company is capturing the same sentiments across cultures—rather, it found sentiments that were recognizable by multiple cultures. If the data miners and user profilers get their way, soon enough we will all be loving, wowing, sadding, and angrying in lockstep.

The language of Reactions is a primitive vocabulary of emotion, vastly simpler than our human languages. It is far better suited to computers and computational analysis. When I introduced graphical emoticons into the Messenger client in 1999, I didn’t foresee any of this. Around 2015, I began noticing a change on my Facebook wall. There was less discussion happening. People I knew were far more content to respond to posts with monosyllables like “yeah” or “ugh,” or with simple emoji or Facebook’s six reactions. I caught myself dumbly contributing like this, to my dismay.

I went back and checked posts from 2009 and 2010. I had written in complete sentences, arguments, with multiple paragraphs. The shift was obvious and drastic. Diversity, nuance, and ambiguity had declined. If passions were fervent, and I disagreed with the chorus of “yeahs” or “ughs,” the crowd was far more likely to pounce on me; the same went for any other dissenters. What had happened? These were my friends. But they no longer seemed like the same people. We had been standardized. We were all speaking a different language now. It was the language of Facebook—of computers.

R tips and tricks – higher-order functions

A higher-order function is a function that takes one or more functions as arguments, and\or returns a function as its result. This can be super handy in programming when you want to tilt your code towards readability and still keep it concise.

Consider the following code:

# Generate some fake data
> eps <- rnorm(10, sd= 5)
> x <- c(1:10)
> y <- 2+2*x + eps
# Load libraries required
> library(quantreg)
> library(magrittr)
> eps <- rnorm(10, sd= 5)
> x <- c(1:10)
> y <- 2+2*x + eps
# create a higher order function
> higher_order_function <- function(func){
+   func(y ~ x) %>% summary
+ }
# Give as an argument the function "lm"
> higher_order_function(lm)


func(formula = y ~ x)
     Min       1Q   Median       3Q      Max 
-12.0149  -0.7603   1.0969   2.7483   4.2373 
            Estimate Std. Error t value Pr(>|t|)   
(Intercept)   1.3214     3.3338   0.396  0.70219   
x             2.1690     0.5373   4.037  0.00375 **
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.88 on 8 degrees of freedom
Multiple R-squared:  0.6708,	Adjusted R-squared:  0.6296 
F-statistic:  16.3 on 1 and 8 DF,  p-value: 0.003751

Now give as an argument the function rq (for regression quantile)

> higher_order_function(rq)
Call: func(formula = y ~ x)
tau: [1] 0.5
            coefficients lower bd upper bd
(Intercept)  3.80788     -1.26475  6.15759
x            1.83968      1.59747  2.98423

It’s also quite safe to use in that if you provide a non-existent function it would not default to some unknown behavior but will return an error:

> higher_order_function(mm)
Error in eval(lhs, parent, parent) : object 'mm' not found

However, this function can be also written as a sequence of if statements, like so

> if_function <- function(x,y, which_reg){ 
+   if (which_reg== "OLS") { lm(y~x) %>% summary }
+   else if (which_reg== "LAD") { rq(y~x) %>% summary }
+ } 

> if_function(x,y, which_reg= "OLS")


lm(formula = y ~ x)
     Min       1Q   Median       3Q      Max 
-12.0149  -0.7603   1.0969   2.7483   4.2373 
            Estimate Std. Error t value Pr(>|t|)   
(Intercept)   1.3214     3.3338   0.396  0.70219   
x             2.1690     0.5373   4.037  0.00375 **
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.88 on 8 degrees of freedom
Multiple R-squared:  0.6708,	Adjusted R-squared:  0.6296 
F-statistic:  16.3 on 1 and 8 DF,  p-value: 0.003751

> if_function(x,y, which_reg= "LAD")
Call: rq(formula = y ~ x)
tau: [1] 0.5
            coefficients lower bd upper bd
(Intercept)  3.80788     -1.26475  6.15759
x            1.83968      1.59747  2.98423

Using higher-order functions does not seem to create any additional computational overhead:

 microbenchmark( higher_order_function(rq), if_function(x, y, "LAD") )

nit: milliseconds
                     expr      min       lq     mean   median       uq
higher_order_function(rq) 1.463210 1.498967 1.563553 1.527253 1.624969
 if_function(x, y, "LAD") 1.468262 1.498464 1.584453 1.618997 1.644462
     max neval
2.280419   100
2.082765   100

 microbenchmark( higher_order_function(lm), if_function(x, y, "OLS") )

nit: microseconds
                     expr     min       lq     mean   median      uq      max
higher_order_function(lm) 916.858 928.8825 946.9838 935.3930 955.791 1025.575
 if_function(x, y, "OLS") 918.674 928.1260 953.2587 938.0465 958.284 1433.167

So you can make your code more concise with little computational overhead.

Learning and Teaching J

We look at an essay by a neurosurgeon on some of the profound misconceptions surrounding artificial intelligence.

Can man ever build a mind?

Artificial intelligence has problems. The biggest is that brains are nothing like computers

by Henry Marsh JANUARY 10, 2019

The idea that we might create machines more intelligent than ourselves is not new. Myths and folk stories abound with creations such as the bronze automaton Talos, who patrolled the island of Crete in Greek mythology. These stories reflect a deep, atavistic fear that there could be other minds that bear the same relationship to us as we do to the animals we eat or keep as pets. With the arrival of artificial intelligence, the idea has re-emerged with a vengeance.

We are condemned to understand new phenomena by analogy with things we already understand, just as the anatomists of old named parts of the brain after fruit and nuts — the amygdala (almonds) and the olives, to name but two. Although Hippocrates, in the fourth century BC, had firmly placed the brain at the centre of human thought and feeling, most early medical authorities had little use for it.

Aristotle thought it was a radiator for cooling the blood. The importance of the brain, for Galen 500 years later, were the fluid cavities — the ventricles — in its centre, and not the tissue of the organ itself. With the rise of scientific method in the 17th century, the brain started to be explained in terms of the latest modern technology. Descartes described the brain and nerves as a series of hydraulic mechanisms. In the 19th century the brain was explained in terms of steam engines and telephone exchanges.

And in the modern era, of course, the brain is seen as a computer. And yet, others argue, any metaphor is deficient: we have never met brains before and lack the appropriate language or concepts. The human brain, it is suggested, will never be able to understand itself. You cannot cut butter with a knife made of butter, as a neuroscience friend recently said to me.

As a neurosurgeon, I have to accept that everything I am thinking and feeling as I write this is a physical phenomenon. Throughout my career I have seen patients who have suffered personality change (almost invariably for the worse) as a result of brain damage — it is difficult to believe in any kind of “mind” separate from the brain’s matter when you see your fellow human beings changed, often grotesquely, in this way. And yet it is a deeply counter-intuitive thought. I remember one of my patients, when I was operating on his brain under local anaesthetic, looking at the computer monitor that showed the view of his brain down the operating microscopic that I was using. “This is the part of your brain which is talking to me at the moment,” I told him, pointing with my instruments to the speech area of his left cerebral hemisphere. He was silent for a while, as he looked at his own brain. “It’s crazy,” he said.

The human brain, it is often stated, is the most complex structure in the known universe. It consists of some 85bn nerve cells, each of which is connected to many thousands of other nerve cells, with some 150tn connections. You can, however, if you wish, reduce it to something that sounds quite simple. Each nerve cell is an input/output device that processes data. The input is electrical stimulation (or inhibition) by the thousands of other nerve cells whose output limbs, called axons, are connected to it via one-way connections called synapses.

The human brain, it is suggested, will never be able to understand itself. You cannot cut butter with a knife made of butter Diagrams of brain nerve cells resemble trees in winter — the tangle of bare branches are the dendrites, where the synapses are found, and the tree trunk is the axon. The output is a train of electrical “spikes” fired down the axon, in response to the input of the nerve cells connected to it via the synapses. The axon is in turn connected to other nerve cells via the synapses on their dendrites. And so it goes, on and on, in a hugely elaborate dance. So, superficially, you might think the brain is a massive array of interconnected electrical switches. With modern, high-speed computers, which are massive arrays of interconnected electrical switches, surely it is only a matter of time before we build computers — artificial intelligences — that are smarter than we are? But how does such a simple design produce the extraordinary richness of human life and thought? And, for that matter, of animal life as well?

Even our profound knowledge of physics and chemistry doesn’t begin to explain how this electro-chemical activity generates conscious experience — the feeling of pain and the redness of the colour red, or the mysterious way that these seemingly identical electro-chemical processes produce sensations such as sound and vision that feel so different. And then there is “the binding problem”: how does all this disparate neuronal activity, spread out in both space and time, produce coherent experience? With vision, for instance, we know that there are separate “centres” for colour and movement and other features such as vertical or horizontal lines; somehow, these bind and resonate together to produce a single image without, as one might naively expect, reporting in to some final integrating centre, synonymous with our sense of self.

The fact that the brain is a physical system must mean, of course, that it is subject to the laws of physics and is therefore computable. As the physicist David Deutsch has argued in his book The Beginning of Infinity, following on from Alan Turing’s groundbreaking paper “On Computable Numbers”, published in 1936, computers are not just another metaphor for the brain like steam engines or telephone exchanges. Computers are “universal simulators” and can, at least in theory, simulate all the information-processing that a human brain carries out, although it might take an almost infinitely long time. This is not to say that the brain is like a computer — a common misconception of Turing’s position.

The fact that the brain must be subject to the laws of physics poses problems for the philosophers, who continue to ponder determinism and free will. Some, such as Daniel Dennett, end up claiming that consciousness and free will are illusions, a position that I, for one, find rather hard to apply to my day-to-day life, especially as I struggle to get out of bed on a cold winter morning. The more interesting questions are the practical ones — how close are computers to matching the human brain? How close are we to understanding how our brains work? And can AI help us understand our brains and vice versa?

The complexity of the brain resides in the way in which the nerve cells are connected. Nerve cells are not, in fact, simple electrical switches. They are formed by organic molecules and not of the silicon and metal of computers. The connection at synapses is carried out by chemicals — neurotransmitters, of which there are upwards of a hundred different types.

Image of the white matter of the brain.jpg An image of the white matter of the brain, produced by the Human Connectome Project, a multi-faculty collaboration that aims to produce a complete 3D wiring diagram of the organ © Courtesy of the USC Laboratory of Neuro Imaging and Athinoula A. Martinos Center for Biomedical Imaging, Consortium of the Human Connectome Project,

Neuronal networks are dynamic — they are constantly changing. They weaken or strengthen in accordance with how much traffic is passing through them. The brain is — to a certain extent — plastic. It can re-programme itself. In blind-folded people, for instance, cortical areas that normally process vision will start processing sound within 48 hours. The brain is topologically complex — it may consist of billions of similar brain cells and their connecting axons — but they are arranged in physically very distinct and precise groups and networks. Furthermore, neurons come in a wide variety of shapes and sizes, even though they all share the same basic plan of dendrites, cell body and axon.

Brains do not come as isolated entities as do computers. They come with bodies, to which they are intimately connected. The bodies are their interface with the world, through which they learn to move, and, some would argue, there cannot be thinking without embodiment. The most plausible explanation for the evolution of brains is that they are prediction devices. To move effectively to find food, shelter and sex, we navigate using a model of the outside world created within our brains. Think of how confusing it is when you go down a staircase and there is one more or one less step than you unconsciously expected, or of the strange feeling as you reach the top of an escalator and the steps shrink. Perception is in large part expectation. Recent research is starting to reveal just how complicated the brain-body relationship can be — intestinal bacteria, for instance, seem to have a significant association with Parkinson’s disease and autism — well, at least in mice. Human brains also come as part of social groups. We are, after all, utterly social creatures.

The philosopher David Hume wrote that “reason is, and ought only to be, the slave of the passions”. Human intelligence is inextricably linked with emotions — the pleasure mathematicians find in an elegant proof, the curiosity that drives a young child to learn by exploring the world, the fear that helps us judge risk. The disembodied, isolated and emotionless “intelligence” of a computer is far removed from all this. This is not to say that true artificial intelligence — leaving aside the serious difficulty of defining the word “intelligence” in the first place — is impossible. It’s just that creating it might be rather difficult.

There are significant practical limitations on the extent to which we can experiment and explore our own brains. The resolution of the best MRI brain scanners, for instance, is about one cubic millimetre, and one cubic millimetre of cerebral cortex can contain up to 100,000 neurons and a billion synapses. The temporal resolution is a little less than one second, and much cerebral activity is measured in milliseconds, so what we see with MRI scans are, in effect, blurred snapshots. Although higher resolutions are possible, they involve immensely strong magnetic fields with which there are many problems. Electrodes inserted into the brain can sometimes be used when operating on patients as part of their treatment work-up, and this can allow very limited experimentation, as can computer-brain interfaces implanted into paralysed patients who can then control, after much practice, robotic arms. But this is, so to speak, only scratching at the surface. We often have to use animals instead, and they can never tell us what they are thinking. Brains do not come as isolated entities as do computers. They come with bodies, to which they are intimately connected.

One of the many major research projects into the human brain is the US-led Human Connectome Project, a multi-faculty collaboration that aims to produce a complete 3D wiring diagram of the brain. This has recently been achieved, but only at intermediate resolution — not down to the level of individual cells and axons — for the mouse brain. It will take decades, not years, to produce the complete connectome of the human brain. One complete connectome has been established — that for the tapeworm C. elegans, which has some 307 neurons and 7,000 synapses. But even this took many years to unravel, and a connectome is only the beginning of trying to understand how a nervous system functions, just as looking at a map of a city is only the beginning of understanding a city. A connectome is necessary but not sufficient. Even when the human connectome has been created, ethical considerations may well limit the extent to which the connectome of dead brains can be related to the thoughts and feelings of living ones.

AI came into existence in the 1950s when the first digital computers were being built. At a famous — some would say infamous — conference at Dartmouth College in 1956, the early AI pioneers, such as Marvin Minsky, confidently asserted that machines would outstrip human intelligence within a few decades. But AI progressed unsteadily over the next four decades, with several “AI winters”, when funding dried up as a result of the signal failure of the field to deliver its promised results.

Early AI pioneer Marvin Minsky with other scientists.jpg The early AI pioneer Marvin Minsky (centre) with other scientists at the Dartmouth Summer Research Project on Artificial Intelligence. The 1956 summer workshop is considered to be the seminal event for AI as a field © Courtesy of the Minsky family

The breakthrough in AI in recent years has resulted from the miniaturisation of computer chips. Computers have become more and more powerful, permitting massive and rapid data processing. It has also been made possible by abandoning attempts to programme computers with symbolic logic, which the early AI pioneers thought held the key to imitating human intelligence. The remarkable progress in AI in recent years is largely based on “neural networks” and machine learning, ideas developed decades ago but only recently put into practice. Neural networks only resemble brain networks in a very loose way. They consist of layered assemblies whose output can feed back and modify their input in accordance with a pre-programmed target, so that they “learn”. They are engines of statistical association and classification. They neither explain nor do they understand. They have no internal model or theory of what is being analysed.

The literature, however, abounds in anthropomorphisms — AI programmes are said to “see” and “think”. Google’s DeepMind programme AlphaGo “vanquished” champion Go player Lee Se-dol. This is all nonsense. It is easy to get carried away. The predictive texting on your smartphone prompts you simply by calculating the probability of the next word from mindless analysis of previous text. Google Translate has trawled the entire contents of the internet without understanding a single word. This statistical approach to AI has nevertheless yielded remarkable results. And yet all current machine intelligences can only perform one task. This form of intelligence is reminiscent of the patients described in some of Oliver Sacks’ writings — people who can carry out remarkable feats of calculation but are utterly helpless in normal society. And yet, despite the profound differences between the deep learning of AIs and organic brains, some recent research by the American neuroscientist Doris Tsao on facial recognition in monkeys shows that the facial recognition area in their brains uses algorithms very similar indeed to the ones used by AIs.

The Holy Grail for AI is “general intelligence” — a computer programme that could not only play games with simple rules but also perform other tasks, such as speech and face recognition, without being re-programmed. On present evidence it looks unlikely that neuronal networks and deep learning will ever be able to do this. Google recently created an AI that could recognise cats in photographs without even training the AI initially with pictures of cats. But this required the AI to be exposed to millions of pictures (it did not “look” at them), whereas a child probably only has to meet a few cats to be able to identify reliably all cats in future.

Simon Stringer, head of the Oxford laboratory for Theoretical Neuroscience and Artificial Intelligence, explains the binding problem: how does disparate neuronal activity, spread out in both space and time, produce coherent experience? © Daniel Stier Simon Stringer explains the binding problem.jpg

The energy consumption of a human brain is 20-30 watts — a dim lightbulb. An exascale computer, capable of a quintillion calculations per second, scaled up to the size of a human brain, would consume hundreds of megawatts. Computer engineers talk of the “von Neumann bottleneck”, a problem with classical computer design in which memory is stored separately from the Central Processing Unit, and one of the reasons why computers use so much energy.

Just as “neural networks” were inspired by biological brains, there is now great interest in “neuromorphic chips”, where computer chips are designed to physically resemble nerve cells rather than merely mimic them in the software program. This should, in principle, make computers much less energy-intensive. The Human Brain Project (HBP), a multi-centre European research effort, funded by the EU to the tune of billions of euros, started with the grand ambition to build a brain — initially of a mouse, then of a human — from the bottom upwards, using computers. By creating a brain out of computer chips, the hope is that we might understand our own brains better. This is a somewhat optimistic inversion of Richard Feynman’s famous remark: “What I cannot create, I do not understand.” Whether the HBP will achieve this or not is highly controversial, given that our current understanding of how brains work is so limited.

One part of the HBP, using neuromorphic design, is Professor Stephen Furber’s experimental and newly launched SpiNNaker computer at Manchester University. It is designed to be both energy-efficient and to run models of brain function, among other things. It is too early to know, he tells me, whether it will lead to major breakthroughs or not, and this unpredictability is, of course, the very essence of science.

There are many other approaches. Simon Stringer and his team at the Oxford Laboratory for Theoretical Neuroscience and Artificial Intelligence have recently published a paper arguing that better theoretical models of neuronal transmission, in particular trying to account for the binding problem, hold more promise of progress. The timing of the firing of nerve cells, and the delays that occur in the time it takes the nerve impulse to travel along axons, could, they argue, be of critical importance in explaining the binding problem. There can be no doubt that much more fundamental research of this kind is required.

I find it strange that some people are so certain that the arrival of “superintelligent” machines is only a matter of time. Filled with a fervour reminiscent of the Second Coming and the Rapture, they talk of the Singularity, a time when AI will equal human intelligence. This belief — which is all it is — often comes with the hope that the human brain and all its contents can be re-written as computer code and that we will find the life everlasting as software programs. These ideas are not to be taken seriously, although they certainly sell books.

The future is always uncertain, and the future of AI and neuroscience is uncertain. Given the vast amount of current research in both fields, it is inevitable that tremendous progress will be made. Machine-learning AIs in their present form are already having a profound economic and social impact and will continue to do so. There is no risk, however, in the foreseeable future, of superintelligent AIs replacing us, or treating us as we have so often treated, and continue to treat, animals. Whether the effects of AI will be beneficial or malign will depend on the uses to which we ourselves put them. As to the possibility of machines acquiring general intelligence — “true AI” as some call it — it’s anybody’s guess. All that is certain is that even if it is possible, it is still a very long way away.

Henry Marsh is a neurosurgeon and author of ‘Do No Harm: Stories of Life, Death and Brain Surgery’ (Weidenfeld & Nicolson)