<jupyter_start><jupyter_text>Dataset<jupyter_code>ex_rate_dataset = pd.read_csv('../data/exchange_rate.txt', parse_dates=False,header=-1, index_col=False)
ex_rate_dataset = ex_rate_dataset.values
print(ex_rate_dataset.shape)
plt.plot(ex_rate_dataset)
plt.show()<jupyter_output>(7588, 8)<jupyter_text>Model<jupyter_code>from keras.layers import Input, Dense, Lambda, concatenate, GRU
from keras.models import Model
from keras.callbacks import EarlyStopping
from keras import backend as K


def fit_model(nb_epoch, batch_size, X, Y):
    inds = np.arange(len(X))
    np.random.seed(10)
    np.random.shuffle(inds)
    X = X[inds]
    Y = Y[inds]
    if K.backend() == 'tensorflow':
        K.clear_session()
    
    D = X.shape[2]
    inp = Input(shape=(X.shape[1],X.shape[2]))
    x = inp
    x = GRU(128, activation='tanh')(x)
    x = MCDropout(0.1)(x)
    mean = Dense(D)(x)
    mean = MCDropout(0.1)(mean)
    log_var = Dense(D)(x)
    log_var = MCDropout(0.1)(log_var)
    out = concatenate([mean, log_var])
    model = Model(inp, out)
    
    def heteroscedastic_loss(true, pred):
        mean = pred[:, :D]
        log_var = pred[:, D:]
        precision = K.exp(-log_var)
        return K.sum(precision * (true - mean)**2. + log_var, -1)
    
    model.compile(optimizer='adam', loss=heteroscedastic_loss)
    print(model.summary())
#     assert len(model.layers[1].trainable_weights) == 3  # kernel, bias, and dropout prob
#     assert len(model.losses) == 5  # a loss for each Concrete Dropout layer
    es = EarlyStopping(monitor='val_loss', min_delta=0, patience=20)
    
    
    hist = model.fit(X, Y, nb_epoch=nb_epoch, batch_size=batch_size, verbose=2, callbacks=[es],
            validation_split=0.20, shuffle=False)
    loss = hist.history['loss'][-1]
    return model, -0.5 * loss


#Multiple resolutions of our model
steps = [1, 2, 5, 10, 25, 50]
ts = ex_rate_dataset
lag = 500 
final_horizon = 50
horizon = 1 
test_length = int(0.3*ts.shape[0])
ts, means, scales = _standardize(ts)
print(ts.shape)

train = []
train_label = []
test = []
test_label = []
model = []

batch_size=256
epochs = 300

for step in steps:
    rolling_steps = int(final_horizon/step) - 1
    sub_lag = int(lag/step)
    ts_train = []
    ts_train_label = []
    
    for i in range(ts.shape[0]-(sub_lag-1+horizon)*step):    
        indices = [i + step*j for j in range(sub_lag)]
        ts_train.append(np.take(ts, indices, axis=0))
        ts_train_label.append(np.take(ts, i+step*(sub_lag-1+horizon), axis =0))
    
    
    ts_test = np.array(ts_train[-test_length-rolling_steps:])
    ts_test_label = np.array(ts_train_label[-test_length-rolling_steps:])
    ts_train = np.array(ts_train[:-test_length-rolling_steps])
    ts_train_label = np.array(ts_train_label[:-test_length-rolling_steps])

    print(ts_train.shape)
    print(ts_train_label.shape)
    print(ts_test.shape)
    print(ts_test_label.shape)
    
    train.append(ts_train)
    train_label.append(ts_train_label)
    test.append(ts_test)
    test_label.append(ts_test_label)
    
    each_model, ELBO = fit_model(epochs,batch_size, ts_train, ts_train_label)
    
    
    
    #save models
    model.append(each_model)<jupyter_output>(7588, 8)
(4763, 500, 8)
(4763, 8)
(2325, 500, 8)
(2325, 8)
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            (None, 500, 8)       0                                            
__________________________________________________________________________________________________
gru_1 (GRU)                     (None, 128)          52608       input_1[0][0]                    
__________________________________________________________________________________________________
mc_dropout_1 (MCDropout)        (None, 128)          0           gru_1[0][0]                      
__________________________________________________________________________________________________
dense_1 (Dense)                 (None, 8)        [...]<jupyter_text>Prediction<jupyter_code>for model_i in model:<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13996273870517, 'fraction_numerical': 0.02887750349324639, 'mean_word_length': 3.3165829145728645, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '249268', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1418, 'n_words': 262, 'path': 'Models/multiresolution_mcdropout_aleatoricloss.ipynb', 'repo_name': 'satyanshukla/Time-Series-Prediction-with-Uncertainty', 'size': '4294'}