forked from humans-to-robots-motion/tp-rmp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big commit: Running and plotting thesis experiments
Signed-off-by: An Thai Le <an.thai.le97@gmail.com>
- Loading branch information
Showing
233 changed files
with
1,004 additions
and
48 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+27 KB
data/tasks/test/models/tphsmm_test3.p → data/tasks/test/models/tphsmm_I1_5.p
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import sys | ||
import argparse | ||
from os.path import join, dirname, abspath | ||
import matplotlib | ||
import numpy as np | ||
import logging | ||
import time | ||
import pickle | ||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
matplotlib.rcParams['pdf.fonttype'] = 42 | ||
matplotlib.rcParams['ps.fonttype'] = 42 | ||
matplotlib.rcParams['font.size'] = 16 | ||
|
||
ROOT_DIR = join(dirname(abspath(__file__)), '..', '..') | ||
sys.path.append(ROOT_DIR) | ||
from tprmp.utils.experiment import Experiment # noqa | ||
|
||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
description='Example run: python experiment.py 1') | ||
parser.add_argument('--mode', help='Load or not', type=int, default=1) | ||
args = parser.parse_args() | ||
|
||
task = 'test' | ||
demo_type = '2D' | ||
demo_names = ['C', 'C1', 'G', 'hat', 'hat1', 'I', 'I1', 'J', 'L', 'L1', 'P', 'S', 'S1', 'S2', 'U'] | ||
start_random_radius = 0.01 | ||
moving_goal_radius = 0.2 | ||
disturb_magnitude = 10. | ||
disturb_period = [50, 150] | ||
disturb = True | ||
v_eps = 5e-2 | ||
goal_eps = 0.2 | ||
Kp = 1 * np.eye(2) | ||
Kd = 0.1 * np.eye(2) | ||
worker = Experiment(task=task, demo_type=demo_type, demo_names=demo_names, start_random_radius=start_random_radius, moving_goal_radius=moving_goal_radius, | ||
disturb_magnitude=disturb_magnitude, disturb_period=disturb_period, v_eps=v_eps, goal_eps=goal_eps) | ||
worker.load_demos() | ||
|
||
if args.mode == 1: | ||
print('Start training models...') | ||
worker.train() | ||
elif args.mode == 2: | ||
print('Tracking experiment...') | ||
error = worker.tracking_experiment() | ||
elif args.mode == 3: | ||
print('Tracking baseline experiment...') | ||
error = worker.tracking_baseline_experiment(Kp, Kd, dt=0.005) | ||
elif args.mode == 4: | ||
print('Adaptation experiment...') | ||
error = worker.adaptation_experiment(disturb=disturb) | ||
elif args.mode == 5: | ||
print('Adaptation with increasing disturb force experiment...') | ||
disturb = True | ||
test_comps = [9] | ||
worker.test_comps = test_comps | ||
disturb_magnitude = 10. * np.arange(1, 10) | ||
error = {} | ||
for dm in disturb_magnitude: | ||
worker.disturb_magnitude = dm | ||
error[dm] = worker.adaptation_experiment(disturb=disturb) | ||
elif args.mode == 6: | ||
print('Adaptation with increasing degree of difference experiment...') | ||
disturb = False | ||
test_comps = [9] | ||
worker.test_comps = test_comps | ||
moving_goal_radius = 0.1 * np.arange(1, 10) | ||
error = {} | ||
for r in moving_goal_radius: | ||
worker.moving_goal_radius = r | ||
error[r] = worker.adaptation_experiment(disturb=disturb) | ||
filename = join(worker.experiment_path, 'experiment_' + str(args.mode) + '_' + str(time.time()) + '.p') | ||
with open(filename, 'wb') as f: | ||
pickle.dump(error, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import sys | ||
import argparse | ||
from os.path import join, dirname, abspath | ||
import matplotlib | ||
import numpy as np | ||
import logging | ||
import time | ||
import pickle | ||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
matplotlib.rcParams['pdf.fonttype'] = 42 | ||
matplotlib.rcParams['ps.fonttype'] = 42 | ||
matplotlib.rcParams['font.size'] = 16 | ||
|
||
ROOT_DIR = join(dirname(abspath(__file__)), '..', '..') | ||
sys.path.append(ROOT_DIR) | ||
from tprmp.utils.experiment import Experiment # noqa | ||
|
||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
description='Example run: python experiment.py 1') | ||
parser.add_argument('--mode', help='Load or not', type=int, default=1) | ||
args = parser.parse_args() | ||
|
||
task = 'pick' | ||
demo_type = '6D' | ||
demo_names = ['sample'] | ||
goal_frame = 'obj_frame' | ||
start_random_radius = 0.01 | ||
omega = 30 * np.pi | ||
N = 10 | ||
moving_goal_radius = 0.1 | ||
disturb_magnitude = 10. | ||
disturb_period = [50, 150] | ||
disturb = False | ||
v_eps = 5e-2 | ||
goal_eps = 0.2 | ||
mass_scale = 0.2 | ||
Kp = 1 * np.eye(6) | ||
Kd = 0.1 * np.eye(6) | ||
worker = Experiment(task=task, demo_type=demo_type, demo_names=demo_names, start_random_radius=start_random_radius, moving_goal_radius=moving_goal_radius, | ||
omega=omega, disturb_magnitude=disturb_magnitude, disturb_period=disturb_period, v_eps=v_eps, goal_eps=goal_eps, goal_frame=goal_frame) | ||
worker.load_demos() | ||
|
||
if args.mode == 1: | ||
print('Start training models...') | ||
worker.train() | ||
elif args.mode == 2: | ||
print('Tracking experiment...') | ||
error = worker.tracking_experiment() | ||
elif args.mode == 3: | ||
print('Tracking baseline experiment...') | ||
error = worker.tracking_baseline_experiment(Kp, Kd, dt=0.005) | ||
elif args.mode == 4: | ||
print('Adaptation experiment...') | ||
error = [] | ||
for n in range(N): | ||
test_omega = omega + np.random.uniform(low=-5, high=5) * np.pi | ||
worker.omega = test_omega | ||
error.append(worker.adaptation_experiment(disturb=disturb)) | ||
elif args.mode == 5: | ||
print('Adaptation with increasing disturb force experiment...') | ||
disturb = True | ||
error = [] | ||
test_comps = [15] | ||
worker.test_comps = test_comps | ||
disturb_magnitude = 10. * np.arange(1, 50, 5) | ||
for n in range(N): | ||
test_omega = omega + np.random.uniform(low=-5, high=5) * np.pi | ||
worker.omega = test_omega | ||
error.append({}) | ||
for dm in disturb_magnitude: | ||
worker.disturb_magnitude = dm | ||
error[n][dm] = worker.adaptation_experiment(disturb=disturb) | ||
elif args.mode == 6: | ||
print('Adaptation with increasing degree of difference experiment...') | ||
disturb = False | ||
test_comps = [15] | ||
worker.test_comps = test_comps | ||
moving_goal_radius = 0.1 * np.arange(1, 10) | ||
error = [] | ||
for n in range(N): | ||
test_omega = omega + np.random.uniform(low=-5, high=5) * np.pi | ||
worker.omega = test_omega | ||
error.append({}) | ||
for r in moving_goal_radius: | ||
worker.moving_goal_radius = r | ||
error[n][r] = worker.adaptation_experiment(disturb=disturb) | ||
filename = join(worker.experiment_path, 'experiment_' + str(args.mode) + '_' + str(time.time()) + '.p') | ||
with open(filename, 'wb') as f: | ||
pickle.dump(error, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import sys | ||
from os.path import join, dirname, abspath | ||
import matplotlib | ||
import logging | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
matplotlib.rcParams['pdf.fonttype'] = 42 | ||
matplotlib.rcParams['ps.fonttype'] = 42 | ||
matplotlib.rcParams['font.size'] = 16 | ||
|
||
ROOT_DIR = join(dirname(abspath(__file__)), '..', '..') | ||
sys.path.append(ROOT_DIR) | ||
from tprmp.utils.loading import load_demos_2d # noqa | ||
from tprmp.models.tp_rmp import TPRMP # noqa | ||
from tprmp.visualization.dynamics import plot_potential_field, plot_dissipation_field # noqa | ||
mode = 1 | ||
task = 'test' | ||
demo_path = join(ROOT_DIR, 'data', 'tasks', task, 'demos') | ||
num_comp = 9 | ||
N1, N2 = 3, 5 | ||
limits = [0., 4.5] | ||
demo_names = ['C', 'C1', 'G', 'hat', 'hat1', 'I', 'I1', 'J', 'L', 'L1', 'P', 'S', 'S1', 'S2', 'U'] | ||
dt = 0.01 | ||
res = 0.05 | ||
|
||
X, Y = np.meshgrid(np.arange(limits[0], limits[1], res), np.arange(limits[0], limits[1], res)) | ||
fig, axs = plt.subplots(N1, N2) | ||
for n, name in enumerate(demo_names): | ||
k, m = int(n / N2), n % N2 | ||
data_file = join(demo_path, name + '.p') | ||
model_file = name + '_' + str(num_comp) + '.p' | ||
demos = load_demos_2d(data_file, dt=dt) | ||
model = TPRMP.load(task, model_name=model_file) | ||
sample = demos[0] | ||
frames = sample.get_task_parameters() | ||
ax = axs[k, m] | ||
plt.sca(ax) | ||
ax.set_xlim([limits[0], limits[1]]) | ||
ax.set_ylim([limits[0], limits[1]]) | ||
if mode == 1: | ||
plot_potential_field(model, frames, limits=limits, new_ax=False, res=res) | ||
else: | ||
plot_dissipation_field(model, frames, limits=limits, new_ax=False, res=res) | ||
|
||
for ax in fig.axes: | ||
try: | ||
ax.label_outer() | ||
except: # noqa | ||
pass | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import sys | ||
from os.path import join, dirname, abspath | ||
import matplotlib | ||
import logging | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.axes_grid1 import make_axes_locatable | ||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
matplotlib.rcParams['pdf.fonttype'] = 42 | ||
matplotlib.rcParams['ps.fonttype'] = 42 | ||
matplotlib.rcParams['font.size'] = 16 | ||
|
||
ROOT_DIR = join(dirname(abspath(__file__)), '..', '..') | ||
sys.path.append(ROOT_DIR) | ||
from tprmp.utils.loading import load_demos_2d # noqa | ||
from tprmp.models.tp_rmp import TPRMP # noqa | ||
from tprmp.visualization.demonstration import _plot_traj_global # noqa | ||
from tprmp.visualization.models import _plot_gmm_global # noqa | ||
|
||
dt = 0.01 | ||
res = 0.05 | ||
limits = [0., 4.5] | ||
task = 'test' | ||
demo_path = join(ROOT_DIR, 'data', 'tasks', task, 'demos') | ||
demo_name = 'S' | ||
data_file = join(demo_path, demo_name + '.p') | ||
num_comp = [5, 9, 15] | ||
|
||
fig, axs = plt.subplots(1, 3) | ||
X, Y = np.meshgrid(np.arange(limits[0], limits[1], res), np.arange(limits[0], limits[1], res)) | ||
for k, n in enumerate(num_comp): | ||
demos = load_demos_2d(data_file, dt=dt) | ||
model_file = demo_name + '_' + str(n) + '.p' | ||
model = TPRMP.load(task, model_name=model_file) | ||
frames = demos[0].get_task_parameters() | ||
ax = axs[k] | ||
ax.set_aspect('equal') | ||
plt.sca(ax) | ||
_plot_traj_global(demos, title=f'{n} components', limits=limits, legend=False, three_d=False, new_ax=False) | ||
_plot_gmm_global(model.model, frames, three_d=False, new_ax=False) | ||
Z = np.zeros_like(X) | ||
model.generate_global_gmm(frames) | ||
for i in range(X.shape[0]): | ||
for j in range(X.shape[1]): | ||
Z[i, j] = model.compute_potential_field(np.array([X[i, j], Y[i, j]])) | ||
c = ax.pcolormesh(X, Y, Z, cmap='RdBu', shading='auto', vmin=0., vmax=50, alpha=0.5) | ||
divider = make_axes_locatable(ax) | ||
cax = divider.append_axes("right", size="5%", pad=0.05) | ||
fig.colorbar(c, cax=cax) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import sys | ||
from os.path import join, dirname, abspath | ||
import matplotlib | ||
import logging | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
matplotlib.rcParams['pdf.fonttype'] = 42 | ||
matplotlib.rcParams['ps.fonttype'] = 42 | ||
matplotlib.rcParams['font.size'] = 16 | ||
|
||
ROOT_DIR = join(dirname(abspath(__file__)), '..', '..') | ||
sys.path.append(ROOT_DIR) | ||
from tprmp.utils.loading import load_demos_2d # noqa | ||
from tprmp.models.tp_rmp import TPRMP # noqa | ||
from tprmp.demonstrations.base import Demonstration # noqa | ||
from tprmp.visualization.demonstration import plot_frame_2d # noqa | ||
from tprmp.demonstrations.manifold import Manifold # noqa | ||
|
||
mode = 1 | ||
task = 'test' | ||
demo_path = join(ROOT_DIR, 'data', 'tasks', task, 'demos') | ||
num_comp = 9 | ||
N1, N2 = 3, 5 | ||
limits = [0., 4.5] | ||
demo_names = ['C', 'C1', 'G', 'hat', 'hat1', 'I', 'I1', 'J', 'L', 'L1', 'P', 'S', 'S1', 'S2', 'U'] | ||
dt = 0.01 | ||
v_eps = 5e-2 | ||
goal_eps = 0.2 | ||
wait = 10 | ||
res = 0.05 | ||
colormap = 'RdBu' if mode == 1 else 'YlOrBr' | ||
manifold = Manifold.get_euclidean_manifold(2) | ||
|
||
|
||
def execute(model, frames, x0, dx0): | ||
x, dx = x0, dx0 | ||
traj = [x] | ||
model.generate_global_gmm(frames) | ||
count = 0 | ||
while True: | ||
ddx = model.retrieve(x, dx) | ||
dx = ddx * dt + dx | ||
x = manifold.exp_map(dx * dt, base=x) | ||
traj.append(x) | ||
if np.linalg.norm(dx) < v_eps: | ||
count += 1 | ||
if count >= wait: | ||
break | ||
else: | ||
count = 0 | ||
return np.array(traj).T | ||
|
||
|
||
X, Y = np.meshgrid(np.arange(limits[0], limits[1], res), np.arange(limits[0], limits[1], res)) | ||
fig, axs = plt.subplots(N1, N2) | ||
for n, name in enumerate(demo_names): | ||
k, m = int(n / N2), n % N2 | ||
data_file = join(demo_path, name + '.p') | ||
if k == 2 and m == 0: | ||
model_file = name + '_' + str(7) + '.p' | ||
else: | ||
model_file = name + '_' + str(num_comp) + '.p' | ||
demos = load_demos_2d(data_file, dt=dt) | ||
model = TPRMP.load(task, model_name=model_file) | ||
sample = demos[0] | ||
frames = sample.get_task_parameters() | ||
x0, dx0 = sample.traj[:, 0], sample._d_traj[:, 0] | ||
traj = execute(model, frames, x0, dx0) | ||
ax = axs[k, m] | ||
plt.sca(ax) | ||
ax.set_aspect('equal') | ||
ax.set_xlim([limits[0], limits[1]]) | ||
ax.set_ylim([limits[0], limits[1]]) | ||
ax.plot(sample.traj[0], sample.traj[1], color="b", linestyle='--', alpha=0.7) | ||
ax.plot(traj[0], traj[1], color="b") | ||
plot_frame_2d(frames.values()) | ||
Z = np.zeros_like(X) | ||
for i in range(X.shape[0]): | ||
for j in range(X.shape[1]): | ||
if mode == 1: | ||
Z[i, j] = model.compute_potential_field(np.array([X[i, j], Y[i, j]])) | ||
else: | ||
Z[i, j] = model.compute_dissipation_field(np.array([X[i, j], Y[i, j]])) | ||
c = ax.pcolormesh(X, Y, Z, cmap=colormap, shading='auto', vmin=0., vmax=Z.max(), alpha=0.5) | ||
fig.colorbar(c, ax=ax) | ||
last = demos[0].traj[:, -1] | ||
plt.scatter(last[0], last[1], marker='*', color='r', s=40) | ||
|
||
for ax in fig.axes: | ||
try: | ||
ax.label_outer() | ||
except: # noqa | ||
pass | ||
plt.show() |
Oops, something went wrong.