<jupyter_start><jupyter_text>HIV Model<NAME><jupyter_code># Configure Jupyter so figures appear in the notebook
%matplotlib inline

# Configure Jupyter to display the assigned value after an assignment
%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'

# import functions from the modsim.py module
from modsim import *
state = State(
    R=200, # activated normal lymphocytes
    L=0, # latently infected
    E=0, # actively infected
    V=4e-7 # free virions

)
system = System(
    gamma=1.36,   # birthrate of R
    mu=1.36e-3,   # natural deathrate of R and L
    delta=0.33,   # deathrate of E
    beta=0.00027, # R-to-L conversion rate (per virion)
    alpha=3.6e-2, # L-to-E rate
    pie=100,      # virion creation rate
    sigma=2,      # virion death rate
    rho=0.1,      # proportion of cells becoming latently infected upon infection
    tau=0.2       # proportion of cells activated
)
def update_func(state, t, system):
    # suggestion from Allison: first calculate named flows here to guarantee conservation
    unpack(system)
    
    dt = 0.2
    dR = gamma * tau - mu * state.R - beta * state.R * state.V
    dL = rho * beta * state.R * state.V - mu * state.L - alpha * state.L
    dE = (1 - rho) * beta * state.R * state.V + alpha * state.L - delta * state.E
    dV = pie * state.E - sigma * state.V
   
    state.R +=dR *dt
    state.L +=dL *dt
    state.E +=dE *dt
    state.V +=dV *dt
    
    return state
    
#state = update_func(state, system)
t0 = 0
t_end = 120

def run_simulation(system, update_func):
    
    unpack(system)
    
    frame = TimeFrame(columns=state.index)
    frame.row[t0] = state
    
    for t in linrange(t0, t_end, 0.2):
        frame.row[t+0.2] = update_func(frame.row[t], t, system)
        
    return frame
results = run_simulation(system, update_func)
def plot_results(R, L, E, V):

    plot(R, '--', label='R')
    plot(L, '-', label='L')
    plot(E, ':', label='E')
    plot(V, '*', label='V')
    decorate(xlabel='Time (days)',
             ylabel='population')
plot_results(results.R, results.L, results.E, results.V)
plot(results.R)
plot(results.E)
plot(results.L)
print('ok')<jupyter_output>ok
{'fraction_non_alphanumeric': 0.12626262626262627, 'fraction_numerical': 0.02203856749311295, 'mean_word_length': 2.836267605633803, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '280751', 'license': 'MIT', 'n_tokens_mistral': 810, 'n_tokens_neox': 773, 'n_words': 214, 'path': 'code/HIV Model.ipynb', 'repo_name': 'aditya-sudhakar/ModSimPy', 'size': '2184'}