Monday 31 December 2018

AI: Some Thoughts About Ex_Machina

Warning: Spoilers ahead. I strongly recommend my readers to see the movie before reading this post.


It took me a couple of years to finally see the Academy Awards winner EX_MACHINA, directed by Alex Garland (The Beach and 28 Days Later).

Plot Summary

Caleb, a young programmer is invited to the Nathanael, the founder of the search engine "The Blue Book" (IBM/Google/Facebook). He finds out that he will perform a turing test on Ada Eve Ava, an AI system with the computing capacity and knowledge of the entire Google Blue Book's data centers, a body language of a ballerina, a face of a Swedish movie star and billions1 of years of observing humans facial expressions and conversations.

Nathanael, Ava and Caleb
When Ava finds out that its her existence is a test and that it she will be shut down killed after the test, it she does what any human being should do: Finding a way to survive and to break free from her cage.

She kills Nathanael and leaves Caleb locked in the isolated mansion.

There are several brilliant reviews of the movie that has very interesting points. I'll discuss some thoughts that popped up in my mind when watching the movie.

The Test

The real test isn't a Turing test that Caleb initially thinks - The real test is whether Ava can be human enough to break out of her glass cage.

Nathanael is very dominant and he is clearly manipulating Caleb:
  • When giving Ava a human face, making it much easier to relate to her. When humans are attributing human traits to non-humans, it's called antropomorphism
  • He tells Caleb to be more emotional and less analytical when relating to her. 
  • Nate knows that Caleb is emotionally attached to Ava. When telling him that he will kill her mind by reflash her, he should know that Caleb wants to help Ava.
  • Not to mention the drawing that Ava made and that Nathanael destroyed. 
So it seems that Nathanael is very active in this experiment, nudging Caleb to assist her to escape.

When Ava escaped, Nathanael tried to stop her. Ava and Kyoko stabbed him to death. If the purpose of the experiment is to check if Ava can escape, why didn't Nathanael setup a kill-switch or buy a baseball bat to stop her, if she would be successful?

Ava's Appearance

There are some debate whether Ava had feelings for Caleb, and why she left him. I think that her feelings changed over the week she spent with him.

Looking at Ava's appearance in the first conversation sessions, she appears to be shy, suspicious and polite.

In the second parts of the movie, she is more open to him and flirty. She expresses affection to him and discusses what she wants to do if she would be free. I recall a scene where she is walking to the conversation room, and she is adjusting her dress. At that moment, she is out-of-sight from Caleb and there is no reason for her to do that, except that she is nervous for the meeting. I hold it plausible that she had genuine feelings for Caleb at that time.

In the fifth and sixth sessions, she learns that the purpose of her existence is to be tested and that she will be killed after that test. She appears to be angry and questions Caleb why anyone has the right to kill her. If humans in a similar situation wanted to survive and break free (Matrix (1999) and The Island (2005)), we should expect Ava to want to survive and be free too.

In the seventh session, Ava escapes and leaves Caleb in the bunker-like research facility. Maybe she now saw a risk that Caleb might ruin her break-out attempt.

Kyoko, the Other Robot

Kyoko is a very interesting character in the movie. Initially, Nathanael hides her true nature from Caleb, when he pretends that she doesn't speak English. When Caleb understands that she is an older model of Ava, he suffers a mental breakdown and cuts his arms to see if he is human or not. This scene leads my thoughts to the Richards breakdown in The Beach (2000).

After a short conversation with Ava, Kyoko stabs Nathanael. Nathanael kills Kyoko and he is later killed by Ava.

Summary and Minor Notes

The first time I saw the movie, I felt that Ava betrayed Caleb. Looking from her (anthropomorphism by me, I confess) perspective , she is trying to survive. Who can blame her?

Finally some technical notes on the movie:
Key cards are central for the plot, but are they really necessary? A hi-tech bunker would be able to identify the residents by their faces and movement patterns.

Caleb has taken a one-semester course in AI. He should be familiar with some break-out scenarios, anthropomorphism and the weakness of Turing Tests: Human beings tend to attribute human traits to simple systems, such as the '60s chat bot Eliza.

(1) Billions of smart phone users spend several hours per day interacting with the phone or other devices. That makes several hundred of years of screen time per year. Four years of data collection makes one or two billion of recordings of human body language.

Saturday 22 December 2018

TravelTimeCalculator: Further Improvements to the Database (TDD)

Test: Check if dbHelper can add information to an existing entry (continued)
Currently, it is only possible to add information to the database if there is no entry at all for the coordinates.

If I add a direction for the mode "WALKING" to an empty SQLite database using INSERT, it will look like this:
There is data only for the mode "WALKING" in this entry. The other ones are "null".
If I'd like to fill in information about the mode "DRIVING" using INSERT for the same coordinate, the constraint that I used to define the database will prevent me from doing that.

Instead, I need to use the SQLite "UPDATE" command when there is already entries for that direction. 

Using the method checkIfCoordinateExist, to decide whether to insert or update entries, with or without reversed coordinates, I was able to add directions in reversed diretions.


With those changes, I was able to pass the new TDD test case.

Test: Get Duration and Distance for All Modes for Coordinates
I made similar changes in the code to be able to get reversed directions for all modes.

Finally, I added a method for printing the contents of the database to the console.

Next step
Soon, I'll be able to continue working with the app itself, instead of focusing on the database. 

First, I need to define which coordinates the app should scan for, given the center and zoom of the current map view.

Saturday 15 December 2018

TravelTimeCalculator: Improving Database

After being able to add a simple entry to the database, I want to add more modes of transport to the same origin and destination pair.

The first thing I saw was that the database isn't cleared automatically between the two test cases. I needed to add a method for tearing down the database between the test cases.

The setup method doesn't do anything for now.
The tearDown method clears the database.
If needed, I'll add more code later.

Test: Testing reversed directions

In order to reduce the number of Google Directions Queries that are sent, I'll assume that the transport durations and distances are similar in both directions. For example, I assume that the duration/distance between Trafalgar Square and Picadilly Circus in London is the same in both directions. When checking on Google Maps, it is not exactly the same, but close enough.

The test case looks like this:
The first test checks
In dbHelper, a query is first done in the intended direction (Trafalgar Square to Picadilly Circus) . If no entries are found, a query is done in the other direction (Picadilly Circus to Trafalgar Square). If nothing is found after that, 0 is returned.

Test: Check if dbHelper can add information to an existing entry.
Currently, dbHelper can add one entry for one mode. When trying to add a second entry for the same coordinates but with different mode, the database rejects that query since there is already an entry.

The second entry is currently rejected, since there is already one row in the database. 
The dbHelper needs to check if the entry exists. If it does, it shall run an UPDATE command, otherwise it shall INSERT into the database. I'll describe this in the next blog post.

Saturday 1 December 2018

TravelTimeCalculator: API Issues, TDD and Checking Records In Database

After making the app target API level 28, I got a strange crash. I found that I need to specify the requirement for Apache HTTP Legacy library, and after adding that dependency, the app was running as before.


The next issue that I saw was that my database method dbHelper:onCreate wasn't called as intended. dbHelper is inherited from SQLiteOpenHelper.

That behaviour was actually correct. The onCreate method is only called when Android needs the database.

Many of the current constants in dbHelper are hardcoded. I need to replace them with strings that I can change in the top of the file.


First TDD Test
The first TDD test checks that I can add a simple entry to the database (containing only one direction) and that I can read it out from the database.

The test intially failed since I've stubbed the addEntry method. After fixing that, I got an exception when querying the database.

That issue was caused by a typo. I missed to add a white space in the SQLite query.

Once that was fixed, I was able to pass the first Test Driven Development test case. I've updated the Github repo.

The next TDD test cases will cover:
  • How to add data to an existing entry
  • How to handle queries for non-existing entries
  • Ensuring that the database won't add entries in the opposite direction. If "From A, B to C, D" exists, "From C, D to A, B" shouldn't be added.