Example #1
0
def generate_zero_columns(data, config):
    # generate 3 additional data column (0 is first column index_
    # 4 hospitalized cumulative,
    # 5 ICU
    # 6
    days = data[:, I_TIME]
    tests = data[:, I_INF]
    dead = data[:, I_DEAD]
    #n = np.ndarray.size(days)
    delay_hos = get_mean(config['delayHOS'])
    delay_hos2 = delay_hos + 1 / get_mean(config['gamma'])
    delay_hosd = get_mean(config['delayHOSD'])
    icufrac = read_icufrac_data(config, days, 0)
    icudfrac = get_mean(config['icudfrac'])
    dfrac = get_mean(config['dfrac'])
    delay_icud = get_mean(config['delayICUD'])

    hoscum = days * 0.0
    hoscumcreate = 'none'
    try:
        hoscumcreate = config['hoscumcreate']
    except:
        pass

    if (hoscumcreate == 'dead'):
        hoscum1 = (1 - icufrac) * gauss_smooth_shift(
            dead, delay_hosd, 0, 1.0 / (dfrac - icufrac * icudfrac))
        hoscum2 = (icufrac) * gauss_smooth_shift(dead, delay_icud, 0, 1.0 /
                                                 (icudfrac))
        hoscum = hoscum1 + hoscum2
    elif (hoscumcreate == 'confirmed'):
        try:
            rate_hoscumfromconfirmed = config['rate_hoscumfromconfirmed']
        except:
            pass
        hoscum = gauss_smooth_shift(tests, delay_hos2, 0,
                                    rate_hoscumfromconfirmed)

    icu = days * 0.0
    hosact = days * 0.0
    datanew = np.concatenate(
        (data[:, 0:4], hoscum[:, None], icu[:, None], hosact[:, None]),
        axis=-1)
    datanew = generate_hos_actual(datanew, config)
    return datanew
Example #2
0
def generate_hos_actual(data, config):
    # generate an additional data column for actual hospitalized
    # only do this when the mean of the actuals are zero

    delay_rec = get_mean(config['delayREC'])
    delay_hos = get_mean(config['delayHOS'])
    delay_hosrec = get_mean(config['delayHOSREC'])
    delay_hosd = get_mean(config['delayHOSD'])
    delay_icu = get_mean(config['delayICUCAND'])
    delay_icud = get_mean(config['delayICUD'])
    delay_icurec = get_mean(config['delayICUREC'])
    hosfrac = get_mean(config['hosfrac'])
    dfrac = get_mean(config['dfrac'])
    t_max = np.size(data[:, I_HOSCUM])
    time = np.linspace(1, t_max, int(t_max))
    icufrac = read_icufrac_data(config, time, 0)
    # icufrac =config['ICufrac']
    icudfrac = get_mean(config['icudfrac'])

    hos = data[:, I_HOS]

    if np.sum(np.cumsum(hos)) > 0.1:
        return data

    # else include the hospitalised column

    hoscum = data[:, I_HOSCUM]

    fracs = [hosfrac, dfrac, icufrac, icudfrac]
    delays = [
        delay_rec, delay_hos, delay_hosrec, delay_hosd, delay_icu, delay_icud,
        delay_icurec
    ]

    dataprocess = do_hospitalization_process(hoscum, delays, fracs)
    hos = dataprocess[:, OP_HOS]
    hos = hos[:, None]
    icucum = dataprocess[:, OP_ICUCUM]
    # print ('day icufrac icucum')
    # for i, ic in enumerate(icucum):
    #     if (i<t_max):
    #         print (time[i], icufrac[i], ic)
    datanew = np.concatenate((data[:, 0:6], hos), axis=-1)
    return datanew
Example #3
0
def parse_config(config, mode='prior'):
    """
    Turns configuration file into parsed model parameters
    :param config: The entire configuration dictionary
    :return: parsed model parameters: params, init_values, alphas_t, m, time, time_delay
    """
    nr_samples = config['nr_prior_samples'] if mode == 'prior' else config[
        'nr_forecast_samples']
    t_max = config['t_max']
    time_delay = config['time_delay']
    population = to_distr(config['population'], nr_samples)
    n = to_distr(config['N'], nr_samples)
    sigma = to_distr(config['sigma'], nr_samples)
    gamma = to_distr(config['gamma'], nr_samples)
    r0 = to_distr(config['R0'], nr_samples)
    alpha = np.array(config['alpha'])
    dayalpha1 = config['dayalpha']
    dayalpha = np.array(dayalpha1)
    dayalpha = (dayalpha + time_delay)
    delay_rec = to_distr(config['delayREC'], nr_samples)
    delay_hos = to_distr(config['delayHOS'], nr_samples)
    delay_hosrec = to_distr(config['delayHOSREC'], nr_samples)
    delay_hosd = to_distr(config['delayHOSD'], nr_samples)
    delay_icu = to_distr(config['delayICUCAND'], nr_samples)
    delay_icud = to_distr(config['delayICUD'], nr_samples)
    delay_icurec = to_distr(config['delayICUREC'], nr_samples)
    hosfrac = to_distr(config['hosfrac'], nr_samples)
    dfrac = to_distr(config['dfrac'], nr_samples)

    # add standard dev for gaussian smoothing
    rec_sd = to_gauss_smooth_dist(config['delayREC'], nr_samples)
    hos_sd = to_gauss_smooth_dist(config['delayHOS'], nr_samples)
    hosrec_sd = to_gauss_smooth_dist(config['delayHOSREC'], nr_samples)
    hosd_sd = to_gauss_smooth_dist(config['delayHOSD'], nr_samples)

    icu_sd = to_gauss_smooth_dist(config['delayICUCAND'], nr_samples)
    icud_sd = to_gauss_smooth_dist(config['delayICUD'], nr_samples)
    icurec_sd = to_gauss_smooth_dist(config['delayICUREC'], nr_samples)

    icudfrac = to_distr(config['icudfrac'], nr_samples)
    m = to_distr(config['m'], nr_samples)
    time = np.linspace(0, t_max, int(t_max) + 1)
    icufrac = read_icufrac_data(config, time, time_delay)
    # indep_scaling = [to_distr(config['alphascaling'], nr_samples) for _ in alpha]
    # Make scaling fully correlated
    # alpha_n = [a * indep_scaling[0] for i, a in enumerate(alpha)]
    # Make scalling fully uncorrelated
    # alpha_n = [a * indep_scaling[i] for i, a in enumerate(alpha)]
    #
    # alpha_out = np.array(alpha_n).T.clip(max=0.99)
    # alpha_out = [list(a) for a in alpha_n]
    alpha_dict = [{'type': 'uniform', 'min': a[0], 'max': a[1]} for a in alpha]
    alpha_n = [to_distr(a, nr_samples) for a in alpha_dict]

    return_dict = {'free_param': [], 'm_prior': [], 'locked': {}}
    if np.size(icufrac) == np.size(time):
        return_dict['locked']['icufrac'] = icufrac
        params = [
            n, r0, sigma, gamma, alpha_n, delay_hos, delay_rec, delay_hosrec,
            delay_hosd, delay_icu, delay_icud, delay_icurec, hosfrac, dfrac,
            icudfrac, m, population, icurec_sd, icud_sd, icu_sd, rec_sd,
            hos_sd, hosrec_sd, hosd_sd
        ]
        names = [
            'n', 'r0', 'sigma', 'gamma', 'alpha', 'delay_hos', 'delay_rec',
            'delay_hosrec', 'delay_hosd', 'delay_icu', 'delay_icud',
            'delay_icurec', 'hosfrac', 'dfrac', 'icudfrac', 'm', 'population',
            'icured_sd', 'icud_sd', 'icu_sd', 'rec_sd', 'hos_sd', 'hosrec_sd',
            'hosd_sd'
        ]
    else:
        params = [
            n, r0, sigma, gamma, alpha_n, delay_hos, delay_rec, delay_hosrec,
            delay_hosd, delay_icu, delay_icud, delay_icurec, hosfrac, icufrac,
            dfrac, icudfrac, m, population, icurec_sd, icud_sd, icu_sd, rec_sd,
            hos_sd, hosrec_sd, hosd_sd
        ]
        names = [
            'n', 'r0', 'sigma', 'gamma', 'alpha', 'delay_hos', 'delay_rec',
            'delay_hosrec', 'delay_hosd', 'delay_icu', 'delay_icud',
            'delay_icurec', 'hosfrac', 'icufrac', 'dfrac', 'icudfrac', 'm',
            'population', 'icured_sd', 'icud_sd', 'icu_sd', 'rec_sd', 'hos_sd',
            'hosrec_sd', 'hosd_sd'
        ]

    return_dict['locked']['dayalpha'] = dayalpha
    # return_dict['locked']['icu_sd'] = icu_sd
    # return_dict['locked']['icud_sd'] = icud_sd
    # return_dict['locked']['icurec_sd'] = icurec_sd
    # return_dict['locked']['rec_sd'] = rec_sd
    # return_dict['locked']['hos_sd'] = hos_sd
    # return_dict['locked']['hosrec_sd'] = hosrec_sd
    # return_dict['locked']['hosd_sd'] = hosd_sd

    for i, param in enumerate(params):
        name = names[i]
        return_dict = add_to_dict(return_dict, param, name)
    return_dict['time'] = time
    return_dict['time_delay'] = time_delay

    return return_dict['m_prior'], return_dict
Example #4
0
def parse_config(config, ndata, mode='prior'):
    """
    Turns configuration file into parsed model parameters
    :param config: The entire configuration dictionary
    :param ndata: the number of data days (affecting icufracscale (applied only beyond ndata+timedelay) )
    :param mode  'prior' will give nr_prior_samples, 'seek_N' only one with mean, else nr_forecast_samples
    :param n:   n=0 will taken n from the argument (range 3 times lower- 3 times higher)  otherwise from the json
    :return: parsed model parameters: params, init_values, alphas_t, m, time, time_delay
    """
    nr_samples = 1
    if mode == 'prior':
        nr_samples = config['nr_prior_samples']
    elif mode == 'mean':
        nr_samples = 1
    else:
        nr_samples = config['nr_forecast_samples']
    t_max = config['t_max']
    time_delay = config['time_delay']
    population = to_distr(config['population'], nr_samples)
    n = to_distr(config['N'], nr_samples)
    sigma = to_distr(config['sigma'], nr_samples)
    gamma = to_distr(config['gamma'], nr_samples)
    r0 = to_distr(config['R0'], nr_samples)
    alpha = np.array(config['alpha'])
    dayalpha1 = config['dayalpha']
    dayalpha = np.array(dayalpha1)
    dayalpha = (dayalpha + time_delay)
    delay_rec = to_distr(config['delayREC'], nr_samples)
    delay_hos = to_distr(config['delayHOS'], nr_samples)
    delay_hosrec = to_distr(config['delayHOSREC'], nr_samples)
    delay_hosd = to_distr(config['delayHOSD'], nr_samples)
    delay_icu = to_distr(config['delayICUCAND'], nr_samples)
    delay_icud = to_distr(config['delayICUD'], nr_samples)
    delay_icurec = to_distr(config['delayICUREC'], nr_samples)
    hosfrac = to_distr(config['hosfrac'], nr_samples)
    dfrac = to_distr(config['dfrac'], nr_samples)

    # add standard dev for gaussian smoothing
    rec_sd = to_gauss_smooth_dist(config['delayREC'], nr_samples)
    hos_sd = to_gauss_smooth_dist(config['delayHOS'], nr_samples)
    hosrec_sd = to_gauss_smooth_dist(config['delayHOSREC'], nr_samples)
    hosd_sd = to_gauss_smooth_dist(config['delayHOSD'], nr_samples)

    icu_sd = to_gauss_smooth_dist(config['delayICUCAND'], nr_samples)
    icud_sd = to_gauss_smooth_dist(config['delayICUD'], nr_samples)
    icurec_sd = to_gauss_smooth_dist(config['delayICUREC'], nr_samples)

    r0_scaleseason = -1
    r0_daymaxseason = -1
    try:
        r0_scaleseason = to_distr(config['R0_scaleseason'], nr_samples)
        r0_daymaxseason = to_distr(config['R0_daymaxseason'], nr_samples)
    except:
        pass
    icudfrac = to_distr(config['icudfrac'], nr_samples)
    m = to_distr(config['m'], nr_samples)
    time = np.linspace(0, t_max, int(t_max) + 1)
    icufrac = read_icufrac_data(config, time, time_delay)
    # scaling uncertainty  for future icufraction
    icufracscale_input = 1.0
    try:
        icufracscale_input = config['icufracscale']
    except:
        pass
    icufracscale = to_distr(icufracscale_input, nr_samples)
    # indep_scaling = [to_distr(config['alphascaling'], nr_samples) for _ in alpha]
    # Make scaling fully correlated
    # alpha_n = [a * indep_scaling[0] for i, a in enumerate(alpha)]
    # Make scalling fully uncorrelated
    # alpha_n = [a * indep_scaling[i] for i, a in enumerate(alpha)]
    #
    # alpha_out = np.array(alpha_n).T.clip(max=0.99)
    # alpha_out = [list(a) for a in alpha_n]

    #alpha_dict = [{'type': 'uniform', 'min': a[0], 'max': a[1]} for a in alpha]
    alpha_normal = False
    try:
        alpha_normal = config['alpha_normal']
    except:
        pass
    if (alpha_normal):
        alpha_dict = [{
            'type': 'normal',
            'mean': a[0],
            'stddev': a[1]
        } for a in alpha]
    else:
        alpha_dict = [{
            'type': 'normal',
            'mean': (0.5 * (a[0] + a[1])),
            'stddev': ((1.0 / np.sqrt(12)) * (a[1] - a[0]))
        } for a in alpha]
    alpha_n = [to_distr(a, nr_samples) for a in alpha_dict]

    return_dict = {'free_param': [], 'm_prior': [], 'locked': {}}
    if np.size(icufrac) == np.size(time):
        return_dict['locked']['icufrac'] = icufrac
        params = [
            n, r0, sigma, gamma, alpha_n, delay_hos, delay_rec, delay_hosrec,
            delay_hosd, delay_icu, delay_icud, delay_icurec, hosfrac, dfrac,
            icudfrac, m, population, icurec_sd, icud_sd, icu_sd, rec_sd,
            hos_sd, hosrec_sd, hosd_sd, icufracscale, r0_scaleseason,
            r0_daymaxseason
        ]
        names = [
            'n', 'r0', 'sigma', 'gamma', 'alpha', 'delay_hos', 'delay_rec',
            'delay_hosrec', 'delay_hosd', 'delay_icu', 'delay_icud',
            'delay_icurec', 'hosfrac', 'dfrac', 'icudfrac', 'm', 'population',
            'icurec_sd', 'icud_sd', 'icu_sd', 'rec_sd', 'hos_sd', 'hosrec_sd',
            'hosd_sd', 'icufracscale', 'r0_scaleseason', 'r0_daymaxseason'
        ]
    else:
        params = [
            n, r0, sigma, gamma, alpha_n, delay_hos, delay_rec, delay_hosrec,
            delay_hosd, delay_icu, delay_icud, delay_icurec, hosfrac, icufrac,
            dfrac, icudfrac, m, population, icurec_sd, icud_sd, icu_sd, rec_sd,
            hos_sd, hosrec_sd, hosd_sd, icufracscale, r0_scaleseason,
            r0_daymaxseason
        ]
        names = [
            'n', 'r0', 'sigma', 'gamma', 'alpha', 'delay_hos', 'delay_rec',
            'delay_hosrec', 'delay_hosd', 'delay_icu', 'delay_icud',
            'delay_icurec', 'hosfrac', 'icufrac', 'dfrac', 'icudfrac', 'm',
            'population', 'icurec_sd', 'icud_sd', 'icu_sd', 'rec_sd', 'hos_sd',
            'hosrec_sd', 'hosd_sd', 'icufracscale', 'r0_scaleseason',
            'r0_daymaxseason'
        ]

    return_dict['locked']['dayalpha'] = dayalpha
    return_dict['locked']['ndataend'] = ndata + time_delay

    # return_dict['locked']['icu_sd'] = icu_sd
    # return_dict['locked']['icud_sd'] = icud_sd
    # return_dict['locked']['icurec_sd'] = icurec_sd
    # return_dict['locked']['rec_sd'] = rec_sd
    # return_dict['locked']['hos_sd'] = hos_sd
    # return_dict['locked']['hosrec_sd'] = hosrec_sd
    # return_dict['locked']['hosd_sd'] = hosd_sd

    for i, param in enumerate(params):
        name = names[i]
        return_dict = add_to_dict(return_dict, param, name)
    return_dict['time'] = time
    return_dict['time_delay'] = time_delay

    return return_dict['m_prior'], return_dict