-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue_f.py
More file actions
54 lines (19 loc) · 1.18 KB
/
Copy pathvalue_f.py
File metadata and controls
54 lines (19 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import tensorflow as tf
import numpy as np
from nn_utils import get_FC_model
class ValueFunction():
def __init__(self, input_dim=10):
self.x = tf.placeholder(dtype=tf.float32, shape=(None, input_dim))
self.value = tf.placeholder(dtype=tf.float32, shape=(None, 1)) #value tensor (sorta like label in supervised)
self.network = get_FC_model(self.x, "value_network", True, hidden_size=[128, 128], output_size=1)
self.loss_op = tf.losses.huber_loss(self.value, self.network)
self.optimizer = tf.train.AdamOptimizer(learning_rate=0.001) #TODO decide what optimizer to use
self.train_op = self.optimizer.minimize(self.loss_op)
#Takes states and values, trains, returns loss
def train(self, sess, states, values):
_, output = sess.run((self.train_op, self.loss_op), feed_dict={self.x:states, self.value:values})
return output
#Takes states and does one forward pass of the network, no training
def forward(self, sess, states):
values = sess.run(self.network, feed_dict={self.x:states})
return values