print(start_time)
    # %% enter end_time
    num_times = 180
    end_time = num_times + start_time
    print(end_time)
    # %% Set the initial value for model
    i0 = to_float(infected[start_time])
    r0 = 0.
    s0 = to_float(population) - i0
    d0 = to_float(deaths[start_time])
    #num_times = len(deaths)
    # %%
    infected = infected[start_time:end_time]
    deaths = deaths[start_time:end_time]
    recovered = recovered[start_time:end_time]
    infected = to_float_vec(infected)
    deaths = to_float_vec(deaths)
    recovered = to_float_vec(recovered)
    # %% Set the training data
    x_train = to_float_vec(np.array([infected, deaths]).transpose())
    x_trains = to_float_vec(np.array([x_train]))

    # %% Solve for the initial parameters
    #%%
    def sigmoid(x):
        return 1. / (1 + np.exp(-x))

    def logit(x):
        return np.log(x / (1 - x))

    #%%
Пример #2
0
print(start_time)
# %% enter end_time
num_times = 180
end_time = num_times + start_time
print(end_time)
# %% Set the initial value for model
i0 = to_float(infected[start_time])
r0 = 0.
s0 = to_float(population) - i0
d0 = to_float(deaths[start_time])
#num_times = len(deaths)
# %%
infected = infected[start_time:end_time]
deaths = deaths[start_time:end_time]
recovered = recovered[start_time:end_time]
infected = to_float_vec(infected)
deaths = to_float_vec(deaths)
recovered = to_float_vec(recovered)


#%%
def sigmoid(x):
    return 1. / (1 + np.exp(-x))


def logit(x):
    return np.log(x / (1 - x))


#%%
def minf(x):
Пример #3
0
#num_times = len(deaths)
# %% load the trained model
mypath = './models/model_' + country_code +'experiment' +'_180'
model= tf.keras.models.load_model(mypath)
#%% make dir
if os.name != 'nt':
    if not os.path.exists(r'./img/' + mypath):
        os.makedirs(r'./img/' + mypath)
elif not os.path.exists(r'.\\img\\' + mypath):
    os.makedirs(r'.\\img\\' + mypath)
# %% find the model num_times
#layer = model.layers[-1]
num_times = 180
end_time = start_time+num_times
#%% Set the training data
x_train_old = to_float_vec(np.array([infected,deaths]).transpose())
x_trains_old = to_float_vec(np.array([x_train_old]))
x_train = to_float_vec(np.ones((1)))
x_trains = to_float_vec(np.array([x_train]))
# %% define the SIRD solver
def solve_SIRD_discrete(num_times,beta_t,gamma_t,mu_t,s0,i0,r0,d0):
    S = []
    I = []
    R = []
    D = []

    S.append(s0)
    I.append(i0)
    R.append(r0)
    D.append(d0)
    num_times = len(beta_t)
Пример #4
0
    # %% load the trained model
    mypath = './models/model_' + country_code + '_180'
    model = tf.keras.models.load_model(mypath)
    #%% make dir
    if os.name != 'nt':
        if not os.path.exists(r'./img/' + mypath):
            os.makedirs(r'./img/' + mypath)
    elif not os.path.exists(r'.\\img\\' + mypath):
        os.makedirs(r'.\\img\\' + mypath)
    # %% find the model num_times
    layer = model.layers[-1]
    num_times = layer.output_shape[1]
    end_time = start_time + num_times
    #%% Set the training data
    x_train = to_float_vec(
        np.array([infected[start_time:end_time],
                  deaths[start_time:end_time]]).transpose())
    x_trains = to_float_vec(np.array([x_train]))

    # %% define the SIRD solver
    def solve_SIRD_discrete(num_times, beta_t, gamma_t, mu_t, s0, i0, r0, d0):
        S = []
        I = []
        R = []
        D = []

        S.append(s0)
        I.append(i0)
        R.append(r0)
        D.append(d0)
        num_times = len(beta_t)
num_times = int(input('Enter the days to train:'))
end_time = num_times + start_time
print(end_time)
# %% Set the initial value for model
i0 = to_float(infected[start_time])
r0 = 0.
s0 = to_float(population) - i0
d0 = to_float(deaths[start_time])
#num_times = len(deaths)
# %%
infected = infected[start_time:end_time]
deaths = deaths[start_time:end_time]
recovered = recovered[start_time:end_time]

# %% Set the training data
x_train = to_float_vec(np.array([infected, deaths]).transpose())
x_trains = to_float_vec(np.array([x_train]))


# %% Solve for the initial parameters
def objective(trial):
    beta = trial.suggest_uniform('beta', 0, 1)
    gamma = trial.suggest_uniform('gamma', 0, 1)
    mu = trial.suggest_uniform('mu', 0, 1)

    S = []
    I = []
    R = []
    D = []

    S.append(s0)
#%% initialize a matrix for taining sets
import numpy as np
x_test = []
y_test = []
x_train = []
y_train = []
# %% create the dataset
S = df_confirmed.keys()
import random
test_size = 0.33
S_test = random.sample(list(S), int(test_size * len(S)))
S_train = list(set(S) - set(S_test))

for s in S_test:
    country_code = s
    infected = to_float_vec(df_infected[country_code].values)
    deaths = to_float_vec(df_deaths[country_code].values)
    recovered = to_float_vec(df_recovered[country_code].values)
    population = df_information[df_information.country ==
                                country_code].population.values[0]
    #%% set time vairables
    num_times = len(infected)
    # %% generate
    observe_days = 30
    predict_days = 1
    days = observe_days + predict_days

    for i in range(num_times - days + 1):
        x_test.append(
            np.concatenate([
                infected[i:observe_days + i],