-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_buffer.py
More file actions
72 lines (60 loc) · 2.12 KB
/
test_buffer.py
File metadata and controls
72 lines (60 loc) · 2.12 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import numpy as np
from utils import Buffer, load_prior, distort_prior, squish_traj, CAE, ExplorationPolicy
import torch
np.set_printoptions(precision=4, suppress=True)
import matplotlib.pyplot as plt
# plt.rcParams["font.size"] = 18
filename = "./demos/placing/demo.json"
prior_clean = load_prior(filename)
distorted_prior = distort_prior(prior_clean)
squished_prior = squish_traj(distorted_prior, lamda=10/len(distorted_prior))
# print(len(distorted_prior))
# fig, axs = plt.subplots(subplot_kw=dict(projection='3d'))
# axs.plot(prior_clean[:,1], prior_clean[:,2], prior_clean[:,3], 'bx', label='Demos1')
# axs.plot(squished_prior[:,1], squished_prior[:,2], squished_prior[:,3], 'rx', label='Demos1')
# plt.show()
buffer = Buffer(len(squished_prior))
explorer = ExplorationPolicy(squished_prior, buffer)
explorer.plot_compressions()
for i in range(10):
distorted_prior = distort_prior(prior_clean)
squished_prior = squish_traj(distorted_prior, lamda=10/len(distorted_prior))
squished_waypoints = squished_prior[:,1:]
reward = np.ones(len(squished_prior)) * np.random.choice(np.arange(10))
buffer.push(squished_waypoints, reward)
samples = buffer.sample(5)
print(samples)
print(squished_prior)
residuals = [sample - squished_waypoints for sample in samples]
residuals = np.concatenate(residuals, axis=0)
print(residuals)
# wayp = explorer.explore()
# print(squished_prior)
# print(wayp)
# print(prior_clean)
# print(distorted_prior)
# v1 = torch.FloatTensor(prior_clean)
# l, w = v1.shape
# z = torch.ones(len(v1))
# # print(z.shape)
# v2 = torch.column_stack((z,v1))
# model = CAE(input_dim=w)
# out = model.get_residual(v1)
# print(l, w)
# print(out)
# print(v1)
# print(v2)
# n_waypoints = prior_clean.shape[0]
# buffer = Buffer(n_waypoints=n_waypoints)
# for i in range(50):
# # distorted_prior = distort_prior(prior_clean)
# distorted_prior = np.ones(prior_clean.shape) * i
# rewards = []
# for _ in range(n_waypoints):
# rewards.append(-i)
# buffer.push(distorted_prior, rewards)
# # print(distorted_prior)
# print(buffer.best_sample())
# sample = buffer.sample(1)
# print(sample)
# # print(len(buffer))