# A Mathematical Model for the COVID-19 Pandemic in Tokyo through Changing Point Calculus
## 2 Materials and Methods
### Model Implementation  
We coded the SEIAMD model in Python, using the function _optimize_least_squares_ from the _SciPy_ library to adjust the parameter \(\beta_{i}\) (see Supplementary Materials). Our application reads the officially published records of COVID-19 confirmed cases, discharged patients, deaths, and vaccinations [15,26]. It also reads a table with values for the other parameters of the model. All the obtained files are in the source format, unmodified; so, they will be read as they are provided by the source. The vaccination file is in the streaming JSON format (i.e., ND-JSON). The other files are in CSV format. Then, our code builds an object that will put together all available data for each day, as well as some calculated data (e.g., immunized and immunized by vaccine, which are fulfilled after all records are already created). A list with these records is used for adjusting the parameter \(\beta_{i}\) as follows.  
First, our model is coded as a function that obtains values for the compartments for some time \(t+1\), given the values of the compartments for time \(t\). This is a straightforward implementation of the equations of our model, as shown in Equation (8). Second, we implement a function that compares the values obtained by executing the previous function for some provided compartment values and the actual values that should be, as indicated by the record that corresponds to the day of the values introduced. This function returns the sum of differences for \(N\) (which should be 0), and the \(I\), \(A\), and \(D\) compartments.  
Third, the second function is iteratively provided to the least squares function for each period indicated in the input table of periods. This function performs the adjustment, but it is not independent. Instead, the code joins the values obtained by executing the function of our model (the first function). This way, the least squares is actually adjusting the parameter \(\beta_{i}\) for some time period provided the behavior of the model in the previous time period, which, in turn, is adjusted considering the previous time period, and so on until the first time period is reached. This ensures that the resulting function is less artificial and thus closer to the real behavior measured and provided in the input files.  
We executed this fitting procedure several times. Each execution allowed us to identify a point of change, which will become a point of parameter adjustment for the next execution of the fitting procedure. This way, after all needed change points have been identified, we obtained the fitting parameters required for our SEIAMD model to fit the behavior of the Tokyo population.  
In addition to \(\beta_{i}\) and \(\beta_{a}\), we also defined the parameters \(\lambda\) and \(\sigma\) during our fitting procedure (although they were not adjusted by least squares), taking into account the predominant variant of each period. Thus, we assumed, from [27], that the original strain was the dominant one in the first eleven periods, that the Alpha variant was dominant in periods 12 and 13, the Delta variant between periods 14 and 15 (both included), and the Omicron variant from period 19.  
Finally, we implemented a function that calls the first function for subsequent days to obtain the projection of the \(I\) compartment on time. The resulting projection is shown in the next section.