Saturday 19 March 2016

Diffusion of the dead - Epilogue. Part 2, The results.

Last time, I presented a question that I had been given by PrettyGreen, a PR company that asked me to get involved with their Halloween publicity campaign for the mobile network operator GiffGaff. We also saw how I modelled the problem and this week I present the results and also the Matlab codes that I used, should you want to recreate, or play around, with the solutions.

The advert presenting the characters involved can be found below.

________________________________________________________________
________________________________________

Results
The survival time of each character in ascending order can be found in the table below. This is further complemented by Figure 1, in which we illustrate the health of each combatant over a 60 minute time span.

The first two characters to die are the Dead Girl and Skin Face. Although these two characters are relatively strong their low initial healths mean that the other combatants are able to dispatch them with relative ease. Thus, neither of them last longer than a minute demonstrating that neither of them are able to use their aggression to its fullest. Similarly, Baby Man is next to die, because although he is able to defend himself better, lasting just over a minute, the combatants once again go after the weakest.

Name Survival time
Dead Girl 3 secs
Skin Face 13 secs
Baby Man 1 mins 44 secs
Pumpkin Head 7 mins 9 secs
Tall Guy 10 mins 7 secs
Hero Girl 55 mins 37 secs
Evil Clown Survivor
The next two to die are quite interesting, these are Pumpkin Head and Tall Guy, lasting approximately 7 and 10 minutes respectively. Up until this point the group has simply been killing the current weakest. At the five minute marker this would be Tall Guy, however, as seen in Figure 1, he is able to outlast Pumpkin Head because Tall guys higher agility allows him to defend better.
Eventually, only Evil Clown and Hero Girl are the surviving combatants. This is interesting as it is often the plot of a horror film to have the heroine survive up until the last few moments, when the final kill is unleashed during extended scenes of heightening tensions. This is exactly what is seen in Figure 1. Initially, things are looking good for Hero Girl as she begins the final battle with much more health than Evil Clown. Furthermore, the agility of the Hero Girl and Evil Clown are equal and the highest out of the group. This has kept them safe up until this point because they were able to run away from danger. Similarly, for the 30 minutes after Tall Guy’s death the two characters are able to capably defend themselves and escape each others attacks.

These tropes are used in many horror films: although the heroine is no physical match for the villain, she is able to make up for the lack of strength in terms of speed. It is also a standard horror trend that it should look like the heroine will survive, but then she is subjected to escalating bouts of terror. Although she is able to put up a valiant fight Hero Girl’s life is slowly drained by Evil Clown’s higher strength, ultimately leading to his victory after 55 minutes and with 45 health remaining.

Who'd have thought that the Evil Clown was so dangerous?! And who could have foreseen where such a simple piece of mathematics, based on the modelling of zombies, would take us?

This brings us to the end of this current set of posts. Next time: something completely different.

________________________________________________________________
________________________________________
function Battle_Royale
%Clear computer memory and plots.
clear
close all
clc

options = odeset('RelTol',1e-4,'AbsTol',1e-5); %Options set for the ODE solver.

S=[9  7  6  8  3  8  9]; %Vector of strength values.
A=[7  8  4  3  8  6  3]; %Vector of agility values.
H=[45 65 60 40 90 10 20];%Vector of initial health.
C=S.*A; %The interaction function is scaled by the strength multiplied by the agility.

[T,Y] = ode45(@(t,y) ODES(t,y,C),[0 7000],H,options); % Solve the ODE.

cc=lines(7); % Set the legend colours.
for i=1:7
    %Find the last moment alive.
    YY=Y(:,i);
    YY(YY<0.1)=0;
    index=find(YY,1,'last');
    YY(YY==0)=nan;
    YY(index)=0;

    plot(T/60,YY,'linewidth',3,'color',cc(i,:)); %Plot results.
    t(i)=T(index)/60;
    hold on
end
t %Print out the times of death.
axis([0 60 0 90]) %Set axes.

%Make the plot look nice.
legend('Tall guy','Evil Clown','Pumpkin Head','Baby Man','Hero Girl','Dead Girl','Skin Face','location','northoutside','orientation','horizontal')
xlabel('Time in minutes')
ylabel('Combatant Health')

function dy = ODES(t,y,C)
Terms=y.*C'; %The value of the each combatant's attack.
dy=zeros(7,1); %Preallocation of the variables.
for i=1:7
    indices=[1:i-1,i+1:7]; %Indices to be summed over.
    dy(i)=-heaviside(y(i))/((1+y(i)^2)*2*C(i))*sum(Terms(indices)); %Differential equation.
end

Saturday 5 March 2016

Diffusion of the dead - Epilogue. Part 1, Horror Battle Royale.


Having written and published the article on zombie invasion I thought the story would end there. Of course the media picked it up and I had my 15 minutes of fame on the radio and TV. However, it appears I was very wrong. A PR company, PrettyGreen, contacted me about getting involved with their Halloween publicity campaign for GiffGaff, a mobile network operator. 

Their question was: suppose seven stereotypical characters from horror movies are released in an arena leading to a battle royale, who would survive? The characters are:
  • Tall Guy – A very tall (6,9 ft) escaped convict;
  • Evil Clown – An evil, twisted clown;
  • Pumpkin Head – A man with a pumpkin as a head;
  • Baby Man – A somewhat mental man who has spent is life trapped in a basement;
  • Hero Girl – A normal young girl;
  • Dead Girl – A dead bride;
  • Skin Face – A man with excess skin stapled over his face.
My first thought was how was I going to do this? As mentioned when we first started this set of posts there are many different ways mathematics could answer this question. I decided to use differential equations to model the health of each character. As the characters interact their health would reduce depending on certain factors. Thus, I asked PrettyGreen to provide me with a strength, agility and initial health for each combatant and I used these to simulate who will be the last person standing. They were even kind enough to send me a picture to use with this post.
Figure 1. Hero Girl, Evil Clown, Dead Girl, Tall Guy and Pumpkin Head all having a nice jog in London. Image courtesy of PrettyGreen.
This post is a little more mathematical then normal as I present all the gory equation details. However, do not let this scare you. Hopefully, I provide all the intuitive details you should need in the text. If you just want the brief that appeared in the news, then please look here.
________________________________________________________________
________________________________________
Method
The battle simulation is based on the reduction of each combatant’s initial health at a rate proportional to their meeting with an opponent. Once a combatant’s health has dropped to zero, they are immediately removed from the conflict, whilst the survivors fight on.

The interaction outcome is based on a scaled form of the empirical rule known as the “Law of Mass Action”. Explicitly, the rate of reduction in health is proportional to the attacker’s health, scaled by an inverse square of the defender’s health. Intuitively, this simply means that a reduction in health can only occur when the attacker and defender meet. Moreover as the attacker gets weaker, their attacks do less damage. Equally, as the defender becomes weaker their defence is less effective. The precise form of the interaction term is,
\begin{equation}
\frac{H_a}{1+H_d^2},
\end{equation}
where $H_a$ is the health of the attacker and $H_d$ is the health of the defender. It should be understood that this interaction term is known as a "constitutive equation". This means that it is not based on any fundamental law, but it is postulated because it produces the right kind of dynamics that we would expect. There are many other functions I could have used in its place, however, in using this equation, I am hoping that it is simple enough to capture the general outcomes of the system and, thus, the results will be robust to any small changes that might occur.

From these assumptions we can construct a coupled set of ordinary differential equations that will evolve the battle and predict who will win. The exact form of the equation for combatant $i=1,2,…,7$ is
\begin{equation}
\tau\frac{dH_i}{dt}=\frac{-1}{1+H_i^2}\frac{1}{S_iA_i}\sum_{j\neq i}S_jA_jH_j.
\end{equation}
Note that the equation is only active while $H_i>0$. Also notice that we have scaled the terms with the strength parameter, $S_i$, and agility parameter, $A_i$. Thus, speed is, potentially, just as important as strength. Parameters can be found in the Table 1, below. Finally, we define the initial condition as:
\begin{equation}
H_i{0}=H_{i0}.
\end{equation}

Name and variable Strength, $S_i$ Agility, $A_i$ Initial health, $H_{i0}$
Tall Guy, $H_1$ 9 7 45
Evil Clown, $H_2$ 7 8 65
Pumpkin Head, $H_3$ 6 4 60
Baby Man, $H_4$ 8 3 40
Hero Girl, $H_5$ 3 8 90
Dead Girl, $H_6$ 8 6 10
Skin Face, $H_7$ 9 3 20
The parameters were chosen such that strength and agility were on a scale from 1 to 10, such that higher numbers represent higher strengths and speeds, respectively. The health parameter is on a scale of 0 to 100, with the relative size determining how healthy each character is. It should be noted that in the original data Dead Girl’s health was 0. Understandably, this would make her “dead”, however, it would also suggest that she was unkillable, resulting in her inevitable win. To ensure such a case does not occur I changed her initial health to 10.

Next time I will present the results of the above simulations and demonstrate that although this is only a simple model it produces an outcome that you would expect to see in any good (or bad) horror film. In the mean time, have a go at simulating the system yourself and perhaps vary the interaction rule to see how the results are influenced by this equation.