def __init__(self, config):
"""initialized approximate value function
config should have the following attributes
Args:
device: the device to use computation, e.g. '/gpu:0'
gamma(float): the decay rate for value at RL
history_length(int): input_length for each scale at CNN
n_feature(int): the number of type of input
(e.g. the number of company to use at stock trading)
trade_stock_idx(int): trading stock index
gam (float): discount factor
n_history(int): the nubmer of history that will be used as input
n_smooth, n_down(int): the number of smoothed and down sampling input at CNN
k_w(int): the size of filter at CNN
n_hidden(int): the size of fully connected layer
n_batch(int): the size of mini batch
n_epochs(int): the training epoch for each time
update_rate (0, 1): parameter for soft update
learning_rate(float): learning rate for SGD
memory_length(int): the length of Replay Memory
n_memory(int): the number of different Replay Memories
alpha, beta: [0, 1] parameters for Prioritized Replay Memories
action_scale(float): the scale of initialized ation
"""
self.device = config.device
self.save_path = config.save_path
self.is_load = config.is_load
self.gamma = config.gamma
self.history_length = config.history_length
self.n_stock = config.n_stock
self.n_smooth = config.n_smooth
self.n_down = config.n_down
self.n_batch = config.n_batch
self.n_epoch = config.n_epoch
self.update_rate = config.update_rate
self.alpha = config.alpha
self.beta = config.beta
self.lr = config.learning_rate
self.memory_length = config.memory_length
self.n_memory = config.n_memory
self.noise_scale = config.noise_scale
self.model_config = config.model_config
# the length of the data as input
self.n_history = max(self.n_smooth + self.history_length, (self.n_down + 1) * self.history_length)
print ("building model....")
# have compatibility with new tensorflow
tf.python.control_flow_ops = tf
# avoid creating _LEARNING_PHASE outside the network
K.clear_session()
self.sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=False))
K.set_session(self.sess)
with self.sess.as_default():
with tf.device(self.device):
self.build_model()
print('finished building model!')
评论列表
文章目录