]
# files = []

# Load Data
# file_x = path + files[0]
# data_x = np.genfromtxt(file_x, delimiter=';')[:, 1:5]
# data_x, _ = create_timeseries_matrix(data_x, look_back=20)
# data_x = np.reshape(data_x, (len(data_x), 20, 4))

data_x = np.ones((80, ), dtype=np.float)
data_x = np.reshape(data_x, (1, 20, 4))

start_t = time.clock()
for fn in files:
    new_data = np.genfromtxt(path + fn, delimiter=';')[:, 1:5]
    new_data, _ = create_timeseries_matrix(new_data, look_back=20)
    new_data = np.reshape(new_data, (len(new_data), 20, 4))
    data_x = np.vstack((data_x, new_data))

print('New data shape: {} \nRead+Calc time: {}'.format(data_x.shape,
                                                       time.clock() - start_t))

x_train, x_test = train_test_split(data_x, test_size=0.1)
data_x = None  # Clear memory

# Train AE
encoder, decoder, autoencoder = vae.create_deep_ae((20, 4), 64)

autoencoder.compile(optimizer='nadam', loss='mse')

autoencoder.load_weights(wpath + 'ae_deep_20-4_64.hdf5', by_name=True)
            # xdelta,
            # xdiff1, xdiff2,
            # xlogdiff1, xlogdiff2,
        )))


print('Loading Data...')

train_data = np.genfromtxt(file_x, delimiter=';')
target_data = np.genfromtxt(file_y, delimiter=';')

train_data, target_data = train_data[-limit:, ], target_data[-limit:]

data_x = prepare_data(train_data)
data_y = signal_to_class(target_data, n=nclasses, normalize=normalize_class)
data_x, data_y = create_timeseries_matrix(data_x, data_y, ts_lookback)

# batch_input_shape=(batch_size, timesteps, units)
# data_x = np.reshape(data_x, (data_x.shape[0], ts_lookback, train_data.shape[1]))

# For training validation
train_x, test_x, train_y, test_y = train_test_split(data_x,
                                                    data_y,
                                                    test_size=train_test)

print('Input data shape :', data_x.shape)
print('Train/Test :', len(train_y), '/', len(test_y))

#=============================================================================#
#       P R E P A R E   M O D E L                                             #
#=============================================================================#
Ejemplo n.º 3
0
import numpy as np
from mas_tools.data import create_timeseries_matrix

from files import FILES, PERIODS, CSV


print('Warning! Process may be very long.')
# lpath = 'E:/Projects/market-analysis-system/data/transformed/'
lpath = 'E:/Projects/market-analysis-system/data/normalized/'
spath = 'E:/Projects/market-analysis-system/data/windowed/'

window = 20 # warning! size of file multiply in to window size

for symbol in FILES:
    for tf in PERIODS:
        ## Optimize skip
        if tf == '1' or tf == '5' or tf =='15':
            continue
        ## Read
        data = np.genfromtxt(lpath+symbol+tf+CSV, delimiter=';')
        ## To windowed
        data, _ = create_timeseries_matrix(data, look_back=window)
        ## Save
        np.savetxt(spath+'norm_w_'+str(window)+symbol+tf+CSV, data, fmt='%0.6f', delimiter=';')
        data = None