Bläddra i källkod

add preprocessing directory

phillip.rothenbeck 1 år sedan
förälder
incheckning
980b4230c2
2 ändrade filer med 62 tillägg och 4 borttagningar
  1. 60 1
      src/preprocessing/synthetic_data.py
  2. 2 3
      src/preprocessing/transform_data.py

+ 60 - 1
datasets/synthetic_data.py → src/preprocessing/synthetic_data.py

@@ -42,7 +42,66 @@ class SyntheticDeseaseData:
         else: 
             print('Data has to be generated before plotting!') # Fabienne war hier
 
-        
+class SI(SyntheticDeseaseData):
+    def __init__(self, plotter:Plotter, N=59e6, I_0=1, simulation_time=500, time_points=100, alpha=0.191, beta=0.05) -> None:
+        """This class is able to generate synthetic data of the SI groups for the reduced SIR model. This is done by utiling the SIR model.
+
+        Args:
+            plotter (Plotter): Plotter object to plot dataset curves.
+            N (int, optional): Size of the population. Defaults to 59e6.
+            I_0 (int, optional): Initial size of the infectious group. Defaults to 1.
+            simulation_time (int, optional): Real time for that the synthetic data is supposed to be generated in days. Defaults to 500.
+            time_points (int, optional): Number of time sample points. Defaults to 100.
+            alpha (float, optional): Factor dictating how many people per timestep go from 'Infectious' to 'Removed'. Defaults to 0.191.
+            beta (float, optional): Factor dictating how many people per timestep go from 'Susceptible' to 'Infectious'. Defaults to 0.05.
+        """
+
+        self.N = N
+        self.S_0 = N - I_0
+        self.I_0 = I_0
+
+        self.alpha = alpha
+        self.beta = beta
+
+        super().__init__(simulation_time, time_points, plotter)
+
+    def differential_eq(self, y, t, alpha, beta):
+        """In this function implements the differential equation of the SIR model will be implemented.
+
+        Args:
+            y (tuple): Vector that holds the current state of the three groups.
+            t (_): not used
+            alpha (_): not used
+            beta (_): not used
+
+        Returns:
+            tuple: Change amount for each group.
+        """
+        S, I = y
+        dSdt = -self.beta * ((S * I) / self.N)
+        dIdt = self.beta * ((S * I) / self.N) - self.alpha * I
+        return dSdt, dIdt
+    
+    def generate(self):
+        """This funtion generates the data for this configuration of the SIR model.
+        """
+        y_0 = self.S_0, self.I_0
+        self.data = odeint(self.differential_eq, y_0, self.t, args=(self.alpha, self.beta)).T
+        super().generate()
+
+    def plot(self, title=''):
+        """Plot the data which was generated.
+        """
+        super().plot(('Susceptible', 'Infectious'), title=title)
+
+    def save(self, name=''):
+        if self.generated:
+            COVID_Data = np.asarray([self.t, *self.data]) 
+
+            np.savetxt('datasets/SI_data.csv', COVID_Data, delimiter=",")
+        else: 
+            print('Data has to be generated before plotting!')
+
 
 class SIR(SyntheticDeseaseData):
     def __init__(self, plotter:Plotter, N=59e6, I_0=1, R_0=0, simulation_time=500, time_points=100, alpha=0.191, beta=0.05) -> None:

+ 2 - 3
datasets/transform_data.py → src/preprocessing/transform_data.py

@@ -1,6 +1,5 @@
 import numpy as np
 import pandas as pd
-from datetime import timedelta
 
 from src.plotter import Plotter
 
@@ -157,13 +156,13 @@ def state_based_data(plotter:Plotter, state_name:str, time_range=1200, sample_ra
 
     t = np.arange(0, time_range, 1)
 
-    plotter.plot(t, [S, I], ['S', 'I'], state_name.replace(' ', '_').replace('-', '_'), state_name+' SI', (6,6), xlabel='time / days', ylabel='amount of people')
+    plotter.plot(t, [S, I], ['S', 'I'], state_name.replace(' ', '_').replace('-', '_').replace('ü','ue'), state_name+' SI', (6,6), xlabel='time / days', ylabel='amount of people')
 
     COVID_Data = np.asarray([t[0::sample_rate], 
                              S[0::sample_rate], 
                              I[0::sample_rate]]) 
 
-    np.savetxt(f"datasets/SIR_RKI_{state_name.replace(' ', '_').replace('-', '_')}_{sample_rate}.csv", COVID_Data, delimiter=",")
+    np.savetxt(f"datasets/SIR_RKI_{state_name.replace(' ', '_').replace('-', '_').replace('ü','ue')}_{sample_rate}.csv", COVID_Data, delimiter=",")