<jupyter_start><jupyter_text>Load original network<jupyter_code>socio = tc.load_sociopatterns_hypertext_2009()
socio_result = tc.measure_group_sizes_and_durations(socio)<jupyter_output><empty_output><jupyter_text>Simulate Flockworks accordingly<jupyter_code>fwP_params = estimate_flockwork_P_args(socio,N_time_steps=100,aggregated_network=socio_result.aggregated_network)
fwP = tc.flockwork_P_varying_rates_neighbor_affinity(**fwP_params)
fwP_binned = tc.bin(fwP,dt=20)<jupyter_output><empty_output><jupyter_text>Set disease parameters<jupyter_code>R0 = 2.0                  # number of secondary infections
rho = 1.0 / (24*3600.)    # recovery rate in 1/s
dt = 600                  # bin for sampling
t_simulation = 4*fwP.tmax # simulation_time
t_sample = np.arange(int(t_simulation / dt)+1,dtype=float) * dt 
N = socio.N

N_meas = 30 # measurements per network<jupyter_output><empty_output><jupyter_text>Simulate<jupyter_code>fig, ax = pl.subplots(1,2,figsize=(8,4))

labels = ['SocioPatterns HT 09', 'Flockwork surrogate' ]

for i_tn, tn in enumerate([socio, fwP_binned]):

    # compute the mean degree over the time
    t, k = np.array(tc.mean_degree(tn))
    mean_k = tc.time_average(t, k)    

    # compute the infection rate
    eta = R0 * rho / mean_k
    print eta
    
    # prepare the measured infected curve
    i_sample = np.zeros_like(t_sample)
    
    # count the samples where i(t_simulation) > 0
    succecssful_samples = 0

    for meas in range(N_meas):

        # prepare SIS object
        sis = tc.SIS(N, t_simulation, eta, rho, number_of_initially_infected = 10, prevent_disease_extinction = True)

        # simulate SIS
        tc.gillespie_SIS(tn, sis)

        # get observables
        t = np.array(sis.time)
        i = np.array(sis.I,dtype=float) / N

        # sample from the observables
        this_sample = tc.sample_a_function(t,i,t_sample)
        
        # only count this if i(t_simulation) > 0
        if this_sample[-1] > 0.0:
            succecssful_samples += 1
            i_sample += this_sample
        
        # plot this single simulation        
        ax[1].plot(t_sample,this_sample,c=tc.color_sequence[i_tn],alpha=0.1,lw=1)

    # plot the mean of this simulation
    ax[0].plot(t_sample,i_sample/succecssful_samples,label=labels[i_tn])
    
ax[0].legend()    
ax[0].set_ylim([0,1])
ax[1].set_ylim([0,1])
ax[0].set_xlabel('time')
ax[0].set_ylabel('ratio of infected')
ax[1].set_xlabel('time')
ax[1].set_ylabel('ratio of infected')

fig.tight_layout()
fig.savefig("SIS_ht09_fw.pdf")
fwP.tmax/100
socio
socio.
help(tc.flockwork_P_varying_rates_neighbor_affinity)
pl.figure()
t, k = tc.mean_degree(socio)
t_sample = np.linspace(t.min(), t.max(), 250)
pl.plot(t,k,'-')
t, k = tc.mean_degree(fwP_binned)
pl.plot(t,k,'-')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12054208273894436, 'fraction_numerical': 0.024251069900142655, 'mean_word_length': 3.836206896551724, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '455449', 'license': 'MIT', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1072, 'n_words': 186, 'path': 'jupyter_notebooks/sociopatterns_SIS.ipynb', 'repo_name': 'benmaier/tacoma', 'size': '2804'}