change the expected value in ddpg test
This commit is contained in:
parent
f071a0e62c
commit
090387a176
|
@ -17,27 +17,26 @@ class TestDDPG(unittest.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
torch.manual_seed(0)
|
|
||||||
random.seed(0)
|
random.seed(0)
|
||||||
np.random.seed(0)
|
np.random.seed(0)
|
||||||
|
torch.manual_seed(0)
|
||||||
super(TestDDPG, cls).setUpClass()
|
super(TestDDPG, cls).setUpClass()
|
||||||
boston = datasets.load_boston()
|
boston = datasets.load_boston()
|
||||||
data = boston['data']
|
data = boston['data']
|
||||||
X_train = data[0:500]
|
X_train = data[0:500]
|
||||||
cls.X_test = data[500:]
|
X_test = data[500:]
|
||||||
y_train = boston['target'][0:500].reshape(500, 1)
|
y_train = boston['target'][0:500].reshape(500, 1)
|
||||||
cls.ddpg = DDPG(n_actions=1, n_states=13)
|
ddpg = DDPG(n_actions=1, n_states=13)
|
||||||
for i in range(500):
|
for i in range(500):
|
||||||
knob_data = np.array([random.random()])
|
knob_data = np.array([random.random()])
|
||||||
prev_metric_data = X_train[i - 1]
|
prev_metric_data = X_train[i - 1]
|
||||||
metric_data = X_train[i]
|
metric_data = X_train[i]
|
||||||
reward = y_train[i - 1]
|
reward = y_train[i - 1]
|
||||||
cls.ddpg.add_sample(prev_metric_data, knob_data, reward, metric_data, False)
|
ddpg.add_sample(prev_metric_data, knob_data, reward, metric_data, False)
|
||||||
if len(cls.ddpg.replay_memory) > 32:
|
if len(ddpg.replay_memory) > 32:
|
||||||
cls.ddpg.update()
|
ddpg.update()
|
||||||
|
cls.ypreds_round = ['%.4f' % ddpg.choose_action(x)[0] for x in X_test]
|
||||||
|
|
||||||
def test_ddpg_ypreds(self):
|
def test_ddpg_ypreds(self):
|
||||||
ypreds_round = [round(self.ddpg.choose_action(x)[0], 4) for x in self.X_test]
|
expected_ypreds = ['0.3169', '0.3240', '0.3934', '0.5787', '0.6988', '0.5163']
|
||||||
expected_ypreds = [0.1778, 0.1914, 0.2607, 0.4459, 0.5660, 0.3836]
|
self.assertEqual(self.ypreds_round, expected_ypreds)
|
||||||
for ypred_round, expected_ypred in zip(ypreds_round, expected_ypreds):
|
|
||||||
self.assertAlmostEqual(ypred_round, expected_ypred, places=6)
|
|
||||||
|
|
Loading…
Reference in New Issue