Пример #1
0
def si_likelihood(pop, event_db, alpha, beta):
    """Determine the likelihood of the data from an SI simulation given alpha 
    and beta
    """
    daily_likelihood=[0]*(np.max(event_db.time)-1)
    t=1
    infectious=find_infectious(event_db, t)
    susceptible=find_susceptible(pop, event_db, t)
    for t in range(1, np.max(event_db.time)):
        new_infectious=find_infectious(event_db, t+1)
        new_susceptible=find_susceptible(pop, event_db, t+1)
        infection_probs=infect_prob(pop, alpha, beta, infectious, susceptible)
        def new_infections_func(x):
            return any(susceptible.ind_ID[x] == new_infectious.ind_ID)
        new_infections = map(new_infections_func, susceptible.index)
        daily_likelihood[t-1]=np.prod(np.subtract(1, infection_probs[np.where(np.invert(new_infections))]))*np.prod(infection_probs[np.where(new_infections)])    
        infectious=new_infectious
        susceptible=new_susceptible
    return np.prod(daily_likelihood)
Пример #2
0
def plot_si(pop, event_db, time):
    """This will create a simple scatterplot of susceptible and infectious individuals at
    a given time
    """
    i=find_infectious(event_db, time)
    s=find_susceptible(pop, event_db, time)
    status=pd.DataFrame({"status":np.append(np.repeat("i", i.shape[0]), np.repeat("s", s.shape[0])), 
                         "colour":np.append(np.repeat("k", i.shape[0]), np.repeat("b", s.shape[0])),
                         "ind_ID":np.append(i.ind_ID, s.ind_ID),
                         "x":pop.iloc[np.append(i.ind_ID, s.ind_ID)].x,
                         "y":pop.iloc[np.append(i.ind_ID, s.ind_ID)].y})
    plt.scatter(status.x, status.y, c=status.colour, s=60, edgecolors='none')