Hello!
I created a neural network for time-series forecasting and I would like to run it on GPU.
So I need to make all my opertations tensor.
First of all - splitting of data.
Here is my code:
The question is how to write this code, using tf.while_loop
I created a neural network for time-series forecasting and I would like to run it on GPU.
So I need to make all my opertations tensor.
First of all - splitting of data.
Here is my code:
import tensorflow as tf
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
TRAIN_SPLIT = 300000
future_target = 36
past_history = 720
STEP = 1
df = pd.read_csv('data/USDT_BTC.csv')
df.columns = ['date','high','low','open','close','volume','quoteVolume','weightedAverage']
df['ema'] = df1.close.ewm(span=14).mean()
features_considered = ['open', 'close', 'ema']
features = df[features_considered]
features.index = df['date']
dataset = features.values
def multivariate_data(dataset, target, start_index, end_index, history_size,
target_size, step, single_step=False):
data = []
labels = []
start_index = start_index + history_size
if end_index is None:
end_index = len(dataset) - target_size
#print(history_size)
for i in range(start_index, end_index):
indices = range(i-history_size, i, step)
data.append(dataset[indices])
if single_step:
labels.append(target[i+target_size])
else:
labels.append(target[i:i+target_size])
return np.array(data), np.array(labels)
x_train_multi, y_train_multi = multivariate_data(dataset, dataset[:, 1], 0,
TRAIN_SPLIT, past_history,
future_target, STEP)
x_val_multi, y_val_multi = multivariate_data(dataset, dataset[:, 1],
TRAIN_SPLIT, None, past_history,
future_target, STEP)The main problem is nested loops of tf.while_loop, especially shape_invariants. I need to take care of the shape of my result data and one more thing that I understood: the shape of the result data must be the same as the shape of the loop indexes. The question is how to write this code, using tf.while_loop
