Tag Archives: chaos

Where Black Mirror’s “Hang the DJ” Goes Wrong

Charlie Brooker’s Black Mirror offers an incisive perspective on how the human struggle adapts as technology progresses. The episode, “Hang the DJ,” (HtDJ) is a story about what happens when an algorithm can predict love.

Wait a second … that’s what Nanaya does!

In my last post, I described how the algorithm in HtDJ works. This time, I’ll describe why the HtDJ doesn’t work in terms of the computer science and human psychology, as well as how Nanaya compares to HtDJ.

What HtDJ and its Algorithm Get Wrong

While much of the HtDJ’s app algorithm is feasible to code there’s a lot about it that could be done better, or simply would not work in a reasonable way. For example, the bots in the simulation are exposed to a limited set of interactions.

Real Life is More Complex

Consider that we never see Frank (Joe Cole) go to work, Amy (Georgina Campbell) deal with her parents, Frank deal with Amy’s parents – and so on. We also never see Amy and Frank experience non-monogamy. These sorts of interactions happen in real life and indicate a lot about who people are both in and out of relationships.

To generalize, the characters never dealt with the concept of scarcity, except, notably, the scarcity of time. In the real world one can imagine a scenario if Frank were to come back from work disappointed by not getting a raise. It would inject a real-life interaction into the relationship. Frank is providing less money, a planned vacation may not be taken, and resulting with Amy to also be disappointed and to perhaps harbor resentment for Frank’s middling ambition.

A weak way to resolve this gap without significantly burdening the simulation would be “fabricating” emotional memories based on what the dating app observes from the user in their real life. This could be done by appending to a user’s emotional memory during a non-interacting period (like the bot’s simulated sleep).

Even simpler, and possibly more impactful, is taking time off from relationships. In HtDJ, the user’s bot is paired with another bot immediately after their previous relationship ends. In reality, people learn a lot during durations of singledom as they reflect on who they are and what they want from their next relationship. So, if we assume that the app can accurately evolve people such that they learn from experiences, it really, really needs to model being single.

To add these types of interactions in the simulation would be to fundamentally assume the way in which bot individuality evolves is representative of how a real-life user would evolve.

Modeling Real-Life Dynamics is Tough

There are several reasons why this is essentially impossible. One reason that I’ve already described before on the blog is chaos. Or maybe Ian Malcolm can summarize it:


Specifically, a computer simulation describing evolving human behavior is almost guaranteed to diverge dramatically from real-life behavior to the point that artificial patterns of behaviors will emerge leading to significant error.

In other words, if bots in the simulation evolve identically to people in real life – the simulation could still be completely off-base just because someone’s individuality was measured within some standard measurement error. For instance, Amy was scored to be an extrovert with a score of 50±2. If her true, real-life extroversion were actually 52 divergences can be expected. Moreover, because how you define simulated individuality will vary based on convention, there is no fundamentally correct mapping to real-life individuality – the predictive power of such a time-variable approach is significantly limited even if the core nature of the simulation and real life are identical.

As it is unlikely the simulation can accurately describe individuality, interactions, and memory completely, synthetic patterns of interactions and emotions will be created. These synthetic emotions would then be used in the rebellion scoring routine in a manner that would simply not be accurate.

So, if a simulation can’t be expected to model real-life evolution of human behaviors, what’s the value of a system simulating dynamic behavior? I believe that the dynamic modeling is a waste given the vast computation required. In general, it’s highly unlikely that any of HtDJ’s simulations would have rendered graphics and simulate the environment because you would have to write code and pay for processing time that isn’t required to arrive at the solution.

HtDJ’s Similarities to the Nanaya Algorithm

At the core of both algorithms is the notion of matching individuals, evolving their relationships in some manner, and comparing scores of romantic options to determine an optimal solution. No other dating apps do this: only Nanaya in real life and HtDJ’s system in fiction.

Simulated Partners

HtDJ featured a lot of nameless partners that Amy and Frank had. Were these based on real people? Were they made up by the algorithm? I think it’s pretty safe to assume HtDJ picks partners based on who is on the app in your area. However, it’s unclear if the partners it picks are actually those a user might date.

For instance, Frank’s first partner after Amy was not only uninterested in Frank but also didn’t seem to share any compatibility whatsoever. In real life, it’s hard to imagine there would even be a first date between them.

On the other hand, the Nanaya algorithm generates fake partners that are those who you have enough in common with such that you might end up dating but later find an incompatibility with. This approach is not just more realistic but also reduces wasteful computation.

Ultimately the core difference is precisely that HtDJ’s system’s bots exist and evolve in scaled time. If you accept the reasons discussed above, then dynamic simulation of bot individuality is not computational efficient. You will spend a lot of effort simulating the dynamics of relationships in a way that has no bearing on reality. So why bother?

Simulation Decisions

A scoring solution based on static variables is Nanaya’s alternative method. In other words, the Nanaya algorithm uses simple equations to estimate value of a relationship based on the initial conditions of your identity. There would be no point having bots grow and learn in the simulation because it’s just not accurate enough. As soon as it’s not worth it for bots to learn – there’s no point in simulating a timeline!

Now instead of 1,000 timelines, you simulate 5,000, or even 10,000, possible partners in addition to the matched partner. Without timelines and dynamically evolving bots, the “rebellions” in HtDJ are unnecessary and can be simplified to comparing scores from a utility function.

This leads to another key difference. HtDJ’s system only cares about the compatibility with the match for a match score. Nanaya does this but it does two other equally important things. First, it estimates your likelihood of meeting other people you would be compatible with if you choose to not date the prospective or existing partner. Second, it also considers how willing you actually are to settle into a relationship. For instance, a user might have a very compatible match lined up, but what’s does it matter if the user is also content being single?

In summary, Nanaya uses a far simpler way to estimate relationship satisfaction while at the same time does more to account for real-life situations.


Black Mirror’s “Hang the DJ” Explained

Even if you haven’t seen it, there’s a pretty good chance you’ve heard of Charlie Brooker’s series, Black Mirror. In its first two seasons, Black Mirror used its standalone episodes to explore the dark side of upcoming and speculative technologies. New seasons, however, have included more uplifting episodes that depicts technology actually helping peoples’ lives such as Emmy-award winning San Junipero’s time traveling lesbian tryst or Season 4’s Hang the DJ (HtDJ).

If you haven’t seen it, you should. Otherwise, the Verge has a decent recap of it here and you can watch the trailer below:

As HtDJ came to an end with its twist ending, it dawned on me: the app in HtDJ is very much like the algorithm behind Nanaya! Nanaya’s algorithm was published during January 2015 and publicized by the New Scientist. Maybe it’s wishful thinking, but just maybe it was one of many different things that  inspired the script.

Nanaya and the system’s algorithm in HtDJ seemed like they had some similarities. But to actually understand what those similarities are I needed to reverse engineer the HtDJ’s algorithm.

This post offers an overview of how the algorithm behind HtDJ’s system and Nanaya work. Next week, I’ll post the issues with the HtDJ. In the following week I’ll post an even more detailed interpretation of how the HtDJ algorithm works.

How HtDJ’s algorithm works

To really evaluate the effectiveness of the HtDJ system, we need to understand a little bit about how the system’s algorithm works. In short, the algorithm creates matches real-life virtual profiles to see which two matches are most likely to lead to a successful relationship, while comparing it to other possible relationships. That’s not too different from how Nanaya works! The figure below shows the general steps of the HtDJ algorithm.


But to understand how Nanaya’s and HtDJ’s algorithms are different, we need to go into more detail.

For starters, HtDJ’s algorithm creates 1,000 simulations, each one a timeline starting with a 12-hour date between the real-life matches. These real-life users are represented by bots, like virtual Amy and Frank, in a scaled time simulation. After that first date with their real-life matches, both bots are assigned new relationships with different bots for a different duration. Here, the algorithm can be pretty complex – finding the right pairings that force bots to evolve and react the most.

In this way, the simulation can learn more from each relationship and improve accuracy. For any of this to be realistic, the bots need to accurately represent how the real-life user behaves and changes their behavior based on interactions.

After a series of relationships, a certain condition in the algorithm is reached and “pairing day” arrives. That morning, both real-life matches’ bots are given a final opportunity to meet again.  Interestingly, at least in HtDJ, the coach said both Amy and Frank would be matched with a “perfect match” they didn’t know. Essentially they have a choice: rebel against the system (which could conceivably be not accepting Frank and giving up on relationships!) or accept a random relationship. This choice as presented in HtDJ is something that is evaluated in Nanaya as well.

Ironically, their decision to be paired or rebel is a simulated emotional decision. Every dating service that uses numerical matchmaking or the Nanaya algorithm, which uses economic, modeling, defines a consistent and absolute standard of what is a good match. Typically, a good match is one that’s close in the highly dimensional matchmaking space (read more about that here). But in HtDJ’s algorithm, a good match is one that your simulated bot “feels” really good about. This is a paradigm shift in dating apps – emphasizing the emotional sensation of good than what is abstractly considered to be good.

But again, it’s simulated emotion. The emotional decision needs to be mathematically calculated. Some theory of decision-making needs to have been coded or numerically achieved such that a finite set of parameters can be fed into its machinery to come to a single, binary decision.

So how would you even go about attempting to simulation emotions? That’s:

The complicated part

In each relationship, the bots’ personalities can remember, evolve, and learn based on the experiences they have within the simulation, leading to the variability between timelines as different types and durations of relationships occur in each one.

These bot identities and personalities must be explicitly defined in a way that accounts for what we understand as identity and personality in real-life. For instance, there’s inevitably some parameter like extroversion. Imagine the designers of the app in HtDJ have found a way to relate your phone conversations, cell phone photos, text messages, and even biometric data like heart rate relate to extroversion. By snooping in, the app can find out how extroverted you are in a bar after a long day of work or at a public park on a sunny day.

Going deeper, the algorithm can do more if their ex’s are also users. With more information about their past relationship, it’s possible to start classifying what combinations of identities and circumstances just don’t result in healthy, long-term partnerships.

After some time, the app can build a very rich profile of not just how you’re extroverted but many other traits, values, and how it defines emotions. To account for all aspects of personality needed for the simulation, more than tens of thousands of variables are needed (The Nanaya algorithm on the site uses about 1,000 variables, depending on the user).

But this fabric of identity and emotion has to evolve in the simulation. Otherwise Amy and Frank would have rebelled at the start. To evolve all these parameters, many equations or numerical routines, like based on machine learning algorithm, would have to define how any interaction changes identity and emotion.

Between tens and thousands of variables and non-linear equations that relate them and how they change, there’s a lot of room for error. There’s also a lot of computation required, which runs up server bills!

In the next post, I’ll talk about the impacts of these errors and server bills as I describe the issues in the algorithm and what solutions exist.


Chaotic Love: What math can tell us about how relationships evolve

I’m very proud to say that Nanaya solves a problem that hasn’t been solved before: determining the value in time of relationships and the option of possible relationships. The Nanaya algorithm has to be pretty complicated to do all of that – a machine of gears, pulleys, and switches that work together to provide a result. The machine has many parts of which are some have been around for awhile.

For instance, the problem of determining relationship quality and stability has been worked on. My old textbook, Nonlinear Dynamics and Chaos by Steven Strogatz, works out an example. This isn’t exactly how Nanaya works but we can take this as a “simple” example.

To evolve a relationship in time, we need to know a few things:

  1. Who are the people before their relationship begins? That is to say, what are their personalities and life circumstance before the first kiss.
  2. How do their personalities interact?

Because this is math we need these to be quantified. We can do that with personality testing and asking a few other questions.

Now what’s next is to set up a system of differential equations. Specifically, there is an equation for each partner that shows how much their affection changes in time based on who they and their partner are. We can consider the simple example of “Romeo” and “Juliet” from Strogatz.

System of differential equations for our lovers.
System of differential equations for our lovers.

Oh dear. So what do these equations mean?

So R(t) and J(t) are functions of love/hate in time. Let’s use dR/dt as an example, though you’ll notice both equations are very similar. R(t) is Romeo’s affection toward Juliet. When R(t) is positive, he is happy with Juliet; when it’s negative, he’s not. dR/dt is simply how much his affection is changing at any specific point in time based on the shared emotions of the couple.

At time zero we have R(t=0), which is Romeo’s interest in Juliet before the relationship.  J(t) and J(t=0) are the same values for Juliet. The values a and b are factors that multiple the feelings of the couple for a specific person. The larger a is, the more Romeo is happy that he is in love. The larger b is, the more Romeo is happy that Juliet loves him.

Well that’s a lot of math. Of course any model like this is a huge oversimplification of reality. Here we look at two dimensions: how Romeo and Juliet feel about each other. These can be broken into many, many other dimensions based on personality and other factors. The oversimplification is welcome as adding more dimensions allows for very complex behaviors that aren’t very predictable. Essentially, the system becomes chaotic as described by chaos theory.

As complicated as it appears it’s very easy to see what happens for various personalities and initial conditions!

So we can consider a few personality types based on a & b:

  • Excitable lover: where a > 0 and b > 0. For the excitable lover, any positive emotions from either partner just make the person happier and happier.
  • Neurotic lover: where a < 0 and b > 0. For the cautious lover, self-doubt causes affections to diminish but love from a partner can over come it.
  • Narcissistic lover: where a > 0 and b < 0. For the narcissistic lover, personal feelings are more important than how a partner feels.
  • Hater: where a and b < 0. For the hater, any love is toxic. Even if they have early affection, that disappears. The more they’re loved the more they’ll run away.
  • There are special cases where either a and/or b = 0. We don’t like haters around here.

That gives us ten different combinations of relationship types, ignoring those special cases. Even for each pair of relationship types there are several different outcomes. For instance, how identical are their personalities and how attracted are they at the beginning of the relationship? Let’s see a few different test cases.

These are parametric plots. In all these cases the arrow indicates going forward in time. Positive values indicate affection and negative are annoyance or dislike (i.e. top right is mutual affection, bottom right is Romeo loves Juliet but Juliet does not love Romeo, bottom left is mutual dislike). Units are arbitrary!

 Two Identical Excitable Lovers With Mutual Attraction

Figure 1
a = 5; b = 5; c = 5; d = 5; R(0)=0.1; J(0)=0.1

This is the predictable outcome when two excitable lovers, attracted to each other, fall in love. Romeo and Juliet are attracted and that initial attraction just builds in time to create a positive feedback loop of mutual admiration. They go off into a bright, love-filled future.

Two Excitable Lovers With Juliet Not Initially Attracted

Figure 2
a = 3; b = 1; c = 1; d = 1; R(0)=0.1; J(0)= -0.25

 Without being initially attracted, Juliet simply isn’t interested even though Romeo is. Romeo has a persuasive personality, which causes her to change her feelings a little bit but she remains unconvinced. As time goes on, the relationship is simply unsustainable and the two part ways.

Now what happens if Romeo is just a little more persistent? We can tweak the a from 3.0 to 3.106 to find out:

Figure 3
a = 3.106; b = 1; c = 1; d = 1; R(0)=0.1; J(0)= -0.25

In this case, Romeo can cajole Juliet just enough for her to overcome her initial ambivalence or lack of attraction to fall in love. In the near future, it’ll be a one-sided relationship but it will ultimately become more equal in love over time.

A Neurotic and Excitable Lover

Figure 4
a = -2; b = 1; c = 1; d = 1; R(0)=0; J(0)= 0.1

Here we have a neurotic Romeo. A little bit of attraction at the start from Juliet enables a relationship to form but it ends up a bit lopsided. As time goes on, it’s clear to see Juliet does love Romeo “more.” There’s nothing wrong with Juliet per se, just that Romeo needs to learn to love himself apparently.

An Excitable and Narcissistic Lover

Figure 5
a = 1; b = -10; c = 10; d = 1; R(0)=0 ; J(0)= 0.1



A recipe for disaster, it’s an unstable relationship! As soon as the narcissist Romeo feels too loved he wants his freedom but as soon as Juliet pulls away he wants attention. Because Juliet will keep loving Romeo so long as he’s happy, the relationship just oscillates between love and hate. It’s unclear what happens in the end but it’s truly something to avoid unless you really like drama. Maybe someone could write a play about it?

So there you have it, we can try to predict the long-term behavior of relationships with mathematical modeling. Reality is a lot more complicated as human relationships span more dimensions than mutual affection. With those extra dimensions comes the chaos that makes predictions all but impossible. It’s even harder when there’s no truly objective means of assessing personality and integrating life circumstances with personality as a means of determining initial conditions.

But difficulty be damned. At Nanaya, we’ve worked on isolating those most important parameters and determining relative long-term behaviors. We’ve made unpredictable, computationally intensive problems tractable and realistic. With the help of volunteers, we’ve validated our prototype outcomes. As time goes on, we look forward to more data as a means of further validating and improving our theory.