Bot image for Llama-2-13b

Shared conversation

Llama-2-13b ·

SEIRモデルによる感染症シミュレーションサンプルコードを書いてください。

Sure, I'd be happy to help you with a sample code for a SEIR (Susceptible-Exposed-Infected-Recovered) model simulation!

Here's a simple Python code that simulates the spread of a contagious disease in a population, using the SEIR model:

python
import numpy as np
import matplotlib.pyplot as plt

# Define the parameters of the SEIR model
beta = 0.5  # transmission rate (infected individuals infecting susceptible individuals)
eta = 0.1  # exposure rate (susceptible individuals becoming infected)
gamma = 0.1  # recovery rate (infected individuals recovering)

# Define the initial conditions
N = 1000  # total population size
S0 = 900  # number of susceptible individuals at time t=0
I0 = 100  # number of infected individuals at time t=0

# Define the time steps
dt = 1  # time step size
t = np.arange(0, 100, dt)  # time array

# Define the simulation loop
def seir_model(S, I, t):
    # Calculate the number of individuals who become infected at time t
    I_new = beta * S * I / N
    # Calculate the number of individuals who recover at time t
    R_new = gamma * I
    # Update the number of susceptible and infected individuals
    S_new = S - eta * S * I / N
    I_new = I_new + eta * S * I / N
    return [S_new, I_new]

# Run the simulation
S, I = [S0, I0], [0, 0]  # initialize susceptible and infected individuals
for t in t:
    S, I = seir_model(S, I, t)
    plt.plot(t, S, label='Susceptible')
    plt.plot(t, I, label='Infected')
plt.legend()
plt.show()

This code simulates the spread of a contagious disease in a population of 1000 individuals over a period of 100 time steps, using the SEIR model. The transmission rate (beta), exposure rate (eta), and recovery rate (gamma) are all set to 0.5, 0.1, and 0.1, respectively. The initial conditions are set to 900 susceptible individuals and 100 infected individuals. The simulation outputs the number of susceptible and infected individuals at each time step, and plots the number of susceptible and infected individuals over time.

I hope this helps! Let me know if you have any questions or if you'd like me to modify the code in any way.

This conversation may have been edited by the sharer.

Bot image for Llama-2-13b
Talk to Llama-2-13b on Poe