Simulation of the SIRS model in CA with D3.js
In Chapter 7, Predicting Gold Prices, we already studied the basics of a random walk simulation. In this chapter, we will implement a CA in JavaScript using D3.js
to simulate the SIRS model.
In the following screenshot we can see the interface of our simulator. It's a simple interface with a grid of 15 x 15 cells (225 total cells). An Update button that applies the rules to all the cells on the grid (step). A paragraph area that will show the status of different populations in the current step, for example, Susceptible: 35 Infected: 153 Recovered: 37 Step: 4. Finally, a Statistics button that writes a list with all the statistics of each step (susceptible, infected, recovered, and so on) into a text area for plotting purpose:
Inside the head
tag we need to refer to the library:
<html> <head> <script src="http://d3js.org/d3.v3.min.js"></script> </head>
The code is mostly in JavaScript. First, we need to define...