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 15x15 grid of cells (225 cells in total). One button, Update, applies the rules to all the cells on the grid (step). One paragraph area will show the status of different populations in the current step, for example, Susceptible: 35 Infected: 153 Recovered: 37 Step: 4. Finally, a button named Statistics writes a list with all the stats of each step [Susceptible, Infected, Recovered ....] into a text area for the purpose of plotting.
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 JavaScript; first,...