<jupyter_start><jupyter_text>Create matrix for temporal intervention<jupyter_code>times= [1, 2, 3] # temporal boundaries between different contact-behaviour
# prefactors for CW, CS, CO:
interventions = [[0.5,0.2,0.3], # before first time
                 [0.2,0.1,0.1], # between first and second time
                 [0.4,0.5,0.2], # between second and third time
                  [0.7,0.1,0.1]] # for times larger than third time

# generate corresponding contact matrix function
C = generator.interventions_temporal(times=times,interventions=interventions)
# Check: Does the contact matrix function give what it should?

# times at which to evaluate contact matrix function
test_times = [-0.1, 0.5, 1.1, 2.9, 5]
# for each time, we here enter the corresponding row from the "interventions" matrix by hand
test_indices = [0, 0, 1, 2, 3]


for i,t in enumerate(test_times):
    j = test_indices[i]
    print( (CH + interventions[j][0]*CW + interventions[j][1]*CS + interventions[j][2]*CO == C(t)).all() )<jupyter_output>True
True
True
True
True<jupyter_text>Create matrix for population-threshold driven intervention<jupyter_code># For the SIR model, we have 3*M population numbers (S,Ia,Is)
# We now consider M = 1
# (Possible extension: Include class R)

# thresholds for switching
thresholds = np.array([ [0,20,0],
                        [0,40,0],
                         [0, 100, 0]])
# interventions
interventions = [[0.5,0.2,0.3], # before first time
                 [0.2,0.1,0.1], # between first and second time
                 [0.4,0.5,0.2], # between second and third time
                  [0.7,0.1,0.1]] # for times larger than third time

# generate contact matrix function
C = generator.interventions_threshold(thresholds=thresholds,interventions=interventions)

# Note that this contact matrix function now takes 4 arguments!
# C == C(t, S, Ia, Is)
# Check: Does the contact matrix function give what it should?

test_populations = [ [ 10,10,10] ,
                      [0, 10, 10],
                       [10, 50,100],
                      [100,200,0]]

# The function is written so that for a "population vector" state = (S,Ia,Is),
# the intervention with the largest index i such that
# state[j] >= thresholds[index,j] for all j
# is chosen. 
# Put differently, we look for the first row (from above) in the matrix "thresholds" such that
# all population numbers exceed the threshold.

# for each time, we here enter the corresponding row from the "interventions" matrix by hand
test_indices = [0, 0, 2, 3]


for i,e in enumerate(test_populations):
    #
    S = np.array([e[0]])
    Ia = np.array([e[1]])
    Is = np.array([e[2]])
    #
    j = test_indices[i]
    #
    print( (CH + interventions[j][0]*CW + interventions[j][1]*CS + interventions[j][2]*CO == C(0,S,Ia,Is)).all() )<jupyter_output>True
True
True
True
{'fraction_non_alphanumeric': 0.12486809708054872, 'fraction_numerical': 0.042208934224410834, 'mean_word_length': 3.2008862629246675, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '295013', 'license': 'MIT', 'n_tokens_mistral': 974, 'n_tokens_neox': 899, 'n_words': 302, 'path': 'examples/contactMatrix/ex01-SIR.ipynb', 'repo_name': 'ineskris/pyross', 'size': '2843'}