In [1]:
import glob
In [2]:
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import colors as mcolors
from matplotlib import patches
import numpy as np
import pandas as pd
import seaborn.apionly as sns
from scipy import stats
import pymc3 as pm
%matplotlib inline
In [3]:
default_cycler = plt.rcParamsDefault["axes.prop_cycle"]
colorblind_cmaps = ["Dark2", "Set2"]
colorblind_cyclers = {cmap: plt.cycler("color", plt.cm.get_cmap(cmap).colors) for cmap in colorblind_cmaps}
plt.rcParams["axes.prop_cycle"] = colorblind_cyclers["Dark2"]
In [4]:
plt.rc("text", usetex=True)
plt.rc("font", family="serif")
In [5]:
plt.rc("text", usetex=False)
plt.rc("font", family="serif")
In [6]:
import re
FILENAME_PATTERN = "experiment-(\d)_user-(\d+)_run-(\d+)"
filename_regex = re.compile(pattern=FILENAME_PATTERN)
from collections import namedtuple
RunData = namedtuple("RunData", "experiment user run")
BestResult = namedtuple("BestResult", "trace model")
TlxResponse = namedtuple("TlxResponse", "code raw weight score")
Coords = namedtuple("Coords", "x y")
TARGET = Coords(0, 6)
from enum import Enum
DroneState = Enum("DroneState",
"Emergency Inited Landed Flying Hovering Test TakingOff GotoHover Landing Looping",
start=0)
ExperimentType = Enum("ExperimentType", "Onboard Spirit Combined LineOfSight")
In [7]:
def change_color(color, saturation=0, value=0):
rgb = mcolors.ColorConverter.to_rgb(color)
h, s, v = mcolors.rgb_to_hsv(rgb)
s *= 1 + saturation/100
s = np.clip(s, 0, 1)
v *= 1 + value/100
v = np.clip(v, 0, 1)
r, g, b = mcolors.hsv_to_rgb((h, s, v))
return r, g, b
In [8]:
def saturate_color(color, percent):
rgb = mcolors.ColorConverter.to_rgb(color)
h, s, v = mcolors.rgb_to_hsv(rgb)
s *= 1 + percent/100
s = np.clip(s, 0, 1)
r, g, b = mcolors.hsv_to_rgb((h, s, v))
return r, g, b
In [9]:
def shade_color(color, percent):
rgb = mcolors.ColorConverter.to_rgb(color)
h, s, v = mcolors.rgb_to_hsv(rgb)
v *= 1 + percent/100
v = np.clip(v, 0, 1)
r, g, b = mcolors.hsv_to_rgb((h, s, v))
return r, g, b
In [10]:
def plot_overview(df, experiment_type, color="C0", title=None, target=TARGET,
alpha_path=0.2, zorder_path=0,
alpha_point=0.5, zorder_point=1,
xlabel="$x$ (m)", ylabel="$y$ (m)"):
df_ex = df[df.experiment_type == experiment_type]
df_arr = df_ex[df_ex.arrived == 1]
if title is None:
title = df_ex.experiment.iloc[0]
for run in set(df_ex.total_ordering):
df_run = df_ex[df_ex.total_ordering == run]
plt.plot(df_run.xn, df_run.yn, alpha=alpha_path, color=color, zorder=zorder_path)
plt.scatter(df_arr.xn, df_arr.yn, alpha=alpha_point, color=color, zorder=zorder_point)
plot_targets(show_start=True, show_final=False, target_coords=[target])
plt.axis("equal")
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.title(title)
In [11]:
def plot_by_distance(df, experiment_type, cmap="C0", target=TARGET,
alpha_point=0.5, zorder_point=1, crosshair=False,
xlabel="$x$ (m)", ylabel="$y$ (m)"):
df_ex = df[df.experiment_type == experiment_type]
df_arr = df_ex[df_ex.arrived == 1]
plt.scatter(df_arr.xn, df_arr.yn,
c=df_arr.distance, cmap=cmap)
plt.colorbar(label="distance (m)")
plt.clim(df[df.arrived==1].distance.min(), df[df.arrived==1].distance.max())
plot_targets(show_start=False, show_final=False, target_coords=[TARGET], crosshair=crosshair)
plt.axis("equal")
plt.xlabel(xlabel)
plt.ylabel(ylabel)
In [12]:
def plot_detailed(df, experiment_type, color="C0", title=None, target=TARGET,
alpha_point=0.5, zorder_point=1, crosshair=False,
xlabel="$x$ (m)", ylabel="$y$ (m)"):
df_ex = df[df.experiment_type == experiment_type]
df_arr = df_ex[df_ex.arrived == 1]
if title is None:
title = df_ex.experiment.iloc[0]
for order in np.arange(1, df.order.max()+1):
df_run = df_arr[df_arr.order==order]
plt.scatter(df_run.xn, df_run.yn,
label=f"Run {order}", color=shade_color(color, -50+25*(order-1)))
plot_targets(show_start=False, show_final=False, target_coords=[TARGET], crosshair=crosshair)
plt.title(title)
plt.axis("equal")
plt.xlabel(xlabel)
plt.ylabel(ylabel)
plt.legend()
In [13]:
def plot_distribution(df, experiment_type, color="C0", title=None,
target_color="C2", background_shade=-50, crosshair=False):
df_ex = df[df.experiment_type == experiment_type]
df_arr = df_ex[df_ex.arrived == 1]
if title is None:
title = df_ex.experiment.iloc[0]
g = sns.jointplot(df_arr.xn, df_arr.yn, kind="kde", size=7, space=0, color=color)
g.plot_marginals(sns.rugplot, height=0.1, color=color)
g.ax_joint.get_children()[0].set_zorder(-1)
for child in g.ax_joint.get_children()[1:]:
if isinstance(child, mpl.collections.PathCollection):
child.set_alpha(0.8)
plt.sca(g.ax_joint)
plot_targets(show_start=False, show_final=False, target_coords=[TARGET],
target_color=target_color, zorder=0, crosshair=crosshair)
g.set_axis_labels("$x$", "$y$")
plt.axis("equal")
xmin, xmax = plt.xlim()
ymin, ymax = plt.ylim()
xsize = xmax - xmin
ysize = ymax - ymin
if xsize > ysize:
ymin -= (xsize - ysize) / 2
ymax += (xsize - ysize) / 2
ysize = xsize
else:
xmin -= (ysize - xsize) / 2
xmax += (ysize - xsize) / 2
xsize = ysize
plt.gca().add_patch(patches.Rectangle((xmin, ymin), xsize, ysize,
color=saturate_color(color, background_shade), zorder=-1))
g.fig.suptitle(title)
In [14]:
def plot_xy(df, x="x", y="y", invert_x=True, invert_y=True, s=None, c=None,
cmap="viridis", alpha=1, show_cbar=True, label=None, line=False, zorder=0):
"""
Coords in real frame. +x is towards doors, +y is away from table.
"""
if s is not None:
s = df[s]*25
if c is not None:
label = c
try:
df[c]
except KeyError:
pass
else:
c = df[c]
else:
if line:
c = "C0"
else:
c = df.index
label="time"
if line:
plt.plot(df[x] * (-1 if invert_x else 1), df[y] * (-1 if invert_y else 1), c=c, alpha=alpha, zorder=zorder)
else:
plt.scatter(df[x] * (-1 if invert_x else 1), df[y] * (-1 if invert_y else 1), s=s, c=c, cmap=cmap, alpha=alpha, zorder=zorder)
if show_cbar:
plt.colorbar(label=label)
plt.axis("equal")
In [15]:
def plot_xy_conditional(df, condition=None, x="x", y="y", invert_x=True, invert_y=True,
s=None, c=None, c_condition=None, cmap_condition="viridis", cmap_not_condition="gray",
alpha_condition=1, alpha_not_condition=1, show_cbar=True, label=None, line=False,
zorder_condition=1, zorder_not_condition=0):
if condition is None:
cmap_not_condition = cmap_condition
plot_xy(df, x=x, y=y, invert_x=invert_x, invert_y=invert_y,
s=s, c=c, cmap=cmap_not_condition, alpha=alpha_not_condition, show_cbar=show_cbar,
label=label, line=line, zorder=zorder_not_condition)
if condition is not None:
if line:
show_cbar = False
if c_condition is None:
c = "C0"
else:
c = c_condition
plot_xy(df[condition], x=x, y=y, invert_x=invert_x, invert_y=invert_y,
s=s, c=c, cmap=cmap_condition, alpha=alpha_condition, show_cbar=show_cbar,
label=label, zorder=zorder_condition)
In [16]:
def plot_targets(p_init=Coords(0, 0), p_final=Coords(0, 0), invert_x=False, invert_y=False,
target_coords=None, target_coord_offsets=None, target_color="C2",
target_size=Coords(0.525, 0.37), show_start=True, show_final=True,
scale=100, zorder=0, crosshair=False, background_shade=-50):
if target_coords is not None and target_coord_offsets is not None:
raise ValueError("Use either target_coords or target_coord_offsets")
ax = plt.gca()
if target_coords is None:
if target_coord_offsets is None:
target_coord_offsets = TARGET_COORD_OFFSETS
target_coords = [Coords(p_init.x - offset.x, p_init.y - offset.y) for offset in target_coord_offsets]
if show_start:
plt.scatter(-p_init.x, -p_init.y, marker=(5, 0), s=100, c="g")
for coord in target_coords:
if crosshair:
plt.axhline(coord.y, color=shade_color(target_color, background_shade/2), zorder=zorder)
plt.axvline(coord.x, color=shade_color(target_color, background_shade/2), zorder=zorder)
ax.add_patch(patches.Rectangle((coord.x * (-1 if invert_x else 1) - target_size.x / 2,
coord.y * (-1 if invert_y else 1) - target_size.y / 2),
target_size.x,
target_size.y,
color=target_color,
zorder=zorder))
if show_final:
plt.scatter(p_final.x * (-1 if invert_x else 1), p_final.y * (-1 if invert_y else 1), marker=(3, 0), s=scale, c="r")
In [17]:
def tag_data(df):
df["tag"] = (df.arrived.diff(1) != 0).astype('int').cumsum()
In [18]:
def distance(df, target):
return np.sqrt((df.xn - target.x)**2 + (df.yn - target.y)**2)
In [41]:
def usable_filenames():
filenames = sorted([filename for filename in glob.glob("csv/*.csv") if "user-99" not in filename])
for filename in filenames:
if not filename_regex.search(filename):
continue
if "user-99" not in filename:
df = pd.read_csv(filename, parse_dates=["time"])
if any(df.arrived):
yield filename
In [42]:
def extract_run_data(filename):
data = filename_regex.findall(filename)[0]
return RunData(ExperimentType(int(data[0])), int(data[1]), int(data[2]))
In [43]:
def analyze_all():
results = pd.DataFrame(columns="user experiment_type run dist_err x_err y_err "
"dist_std x_std y_std rms rms_x rms_y duration".split())
for i, filename in enumerate(usable_filenames()):
data = extract_run_data(filename)
df = pd.read_csv(filename, parse_dates=["time"])
df.xn *= -1
df.yn *= -1
found = df[df.arrived == 1]
distances = distance(found, TARGET)
dist_err = distances.mean()
dist_std = distances.std()
dx = found.xn - TARGET.x
x_err = dx.mean()
x_std = dx.std()
dy = found.yn - TARGET.y
y_err = dy.mean()
y_std = dy.std()
rms = np.sqrt(np.mean(((found.xn - TARGET.x)**2 + (found.yn - TARGET.y)**2)))
rms_x = np.sqrt(np.mean((dx)**2))
rms_y = np.sqrt(np.mean((dy)**2))
duration = (found.time.iloc[0] - df[df.z > 0.25].time.iloc[0]).total_seconds()
results.loc[i] = [
data.user, data.experiment, data.run,
dist_err, x_err, y_err,
dist_std, x_std, y_std,
rms, rms_x, rms_y, duration
]
return results
In [148]:
def load():
analyses = pd.DataFrame(columns="user experiment_type run dist_err x_err y_err "
"dist_std x_std y_std rms rms_x rms_y "
"idx_start idx_end t_start t_end duration "
"path_length "
"move_x move_l move_r "
"move_y move_b move_f".split())
records = []
for i, filename in enumerate(usable_filenames()):
data = extract_run_data(filename)
df = pd.read_csv(filename, parse_dates=["time"])
df.xn *= -1
df.yn *= -1
df["experiment_type"] = data.experiment
df["user"] = data.user
df["run"] = data.run
records.append(df)
found = df[df.arrived == 1]
distances = distance(found, TARGET)
dist_err = distances.mean()
dist_std = distances.std()
dx = found.xn - TARGET.x
x_err = dx.mean()
x_std = dx.std()
dy = found.yn - TARGET.y
y_err = dy.mean()
y_std = dy.std()
rms = np.sqrt(np.mean(((found.xn - TARGET.x)**2 + (found.yn - TARGET.y)**2)))
rms_x = np.sqrt(np.mean((dx)**2))
rms_y = np.sqrt(np.mean((dy)**2))
t_start = df[df.z > 0.25].time.iloc[0]
t_end = found.time.iloc[0]
duration = (t_end - t_start).total_seconds()
idx_start = df[df.time==t_start].index[0]
idx_end = df[df.time==t_end].index[0]
df_running = df[["xn", "yn"]].iloc[idx_start:idx_end+1]
points = np.array(df_running)
lengths = np.sqrt(np.sum(np.diff(points, axis=0)**2, axis=1))
path = lengths.sum()
diff_x = np.diff(points[:, 0])
move_r = np.abs(np.sum(diff_x[diff_x > 0])) # movement in negative direction
move_l = np.abs(np.sum(diff_x[diff_x < 0])) # movement in positive direction
move_x = move_l + move_r
diff_y = np.diff(points[:, 1])
move_f = np.abs(np.sum(diff_y[diff_y > 0])) # movement in negative direction
move_b = np.abs(np.sum(diff_y[diff_y < 0])) # movement in positive direction
move_y = move_b + move_f
analyses.loc[i] = [
data.user, data.experiment, data.run,
dist_err, x_err, y_err,
dist_std, x_std, y_std,
rms, rms_x, rms_y,
idx_start, idx_end, t_start, t_end, duration,
path,
move_x, move_l, move_r,
move_y, move_b, move_f,
]
results = pd.concat(records, ignore_index=True)
analyses["group"] = (analyses.user % 2).astype(int)
analyses["start"] = [ExperimentType(e % 2 + 1) for e in analyses.user]
analyses["experiment_int"] = [e.value for e in analyses.experiment_type]
analyses["experiment"] = [e.name for e in analyses.experiment_type]
analyses.experiment.replace("Spirit", "SPIRIT", inplace=True)
results["group"] = (results.user % 2).astype(int)
results["start"] = [ExperimentType(e % 2 + 1) for e in results.user]
results["experiment_int"] = [e.value for e in results.experiment_type]
results["experiment"] = [e.name for e in results.experiment_type]
results.experiment.replace("Spirit", "SPIRIT", inplace=True)
results.distance = distance(results, TARGET)
results.dx = results.xn - TARGET.x
results.dy = results.yn - TARGET.y
results["total_ordering"] = ((results.run.diff(1) != 0)
| (results.experiment_int.diff(1) != 0)
| (results.user.diff(1) != 0)).astype('int').cumsum() - 1
for user in set(analyses.user):
df = analyses[analyses.user == user].sort_values(
by="experiment_int", ascending=np.all(analyses[analyses.user==user]
.start==ExperimentType.Onboard))
df["order"] = range(1, len(df) + 1)
for idx in df.index:
analyses.loc[idx, "order"] = int(df.loc[idx, "order"])
results.loc[results.total_ordering==idx, "order"] = int(df.loc[idx, "order"])
for col in ["user", "run", "group", "order"]:
analyses[col] = analyses[col].astype(int)
for col in ["arrived", "order"]:
results[col] = results[col].astype(int)
return results, analyses
In [149]:
results, analyses = load()
In [134]:
analysis.move_x.plot()
analysis.move_y.plot()
analysis.path_length.plot()
Out[134]:
In [136]:
sns.factorplot(data=analysis, hue="experiment", x="order", y="path_length")
Out[136]:
In [137]:
sns.factorplot(data=analysis, hue="experiment", x="order", y="move_x")
Out[137]:
In [138]:
sns.factorplot(data=analysis, hue="experiment", x="order", y="move_y")
Out[138]:
In [141]:
sns.factorplot(data=analysis, x="experiment", y="move_b", kind="bar", )
Out[141]:
In [91]:
analysis[analysis.user==8].index[0]
Out[91]:
In [93]:
analysis.iloc[16]
Out[93]:
In [ ]:
analysis[analysis.user==8].iloc
In [ ]:
analysis[analysis.user==8].loc
In [60]:
filenames = usable_filenames()
In [104]:
_df = pd.read_csv(next(filenames), parse_dates=["time"])
points = np.array(_df[["xn", "yn"]])
lengths = np.sqrt(np.sum(np.diff(points, axis=0)**2, axis=1))
print(lengths.sum())
In [105]:
plt.scatter(_df.xn, _df.yn)
Out[105]:
In [95]:
analysis[["rms_x", "rms_y"]].iloc[15:17]
Out[95]:
In [106]:
points
Out[106]:
In [112]:
len(points[:, 0]
Out[112]:
In [113]:
np.sum(np.diff(np.abs(points[:, 0])))
Out[113]:
In [120]:
diff = np.diff(points[:, 1])
np.sum(diff[diff > 0]) # movement in negative direction
np.sum(diff[diff < 0]) # movement in positive direction
In [108]:
np.sum(np.diff(points[points[:, 0] > 0][:, 0]))
Out[108]:
In [95]:
def load_all():
frames = []
for filename in usable_filenames():
df = pd.read_csv(filename, parse_dates=["time"])
data = extract_run_data(filename)
df["experiment_type"] = data.experiment
df["user"] = data.user
df["run"] = data.run
frames.append(df)
result = pd.concat(frames, ignore_index=True)
result.xn *= -1
result.yn *= -1
return result
In [178]:
def parse_tlx_component(component):
return TlxResponse(component.code, component.score, component.weight, component.weighted_score)
In [136]:
def best(sample1, sample2, σ_range, exponential_m, n_iter=2000, n_jobs=2):
print(σ_range, exponential_m)
y1 = np.array(sample1)
y2 = np.array(sample2)
y = pd.DataFrame(dict(value=np.r_[y1, y2],
group=np.r_[["onboard"]*len(sample1),
["spirit"]*len(sample2)]))
μ_m = y.value.mean()
μ_s = y.value.std() * 2
with pm.Model() as model:
group1_mean = pm.Normal("group1_mean", μ_m, sd=μ_s)
group2_mean = pm.Normal("group2_mean", μ_m, sd=μ_s)
σ_low, σ_high = σ_range
group1_std = pm.Uniform("group1_std", lower=σ_low, upper=σ_high)
group2_std = pm.Uniform("group2_std", lower=σ_low, upper=σ_high)
ν = pm.Exponential("ν_minus_one", abs(1/(exponential_m-1))) + 1
λ1 = group1_std**-2
λ2 = group2_std**-2
group1 = pm.StudentT("onboard",
nu=ν, mu=group1_mean, lam=λ1, observed=y1)
group2 = pm.StudentT("spirit",
nu=ν, mu=group2_mean, lam=λ2, observed=y2)
diff_of_means = pm.Deterministic("difference of means",
group1_mean - group2_mean)
diff_of_stds = pm.Deterministic("difference of stds",
group1_std - group2_std)
effect_size = pm.Deterministic("effect size",
diff_of_means / np.sqrt((group1_std**2
+ group2_std**2)
/ 2))
trace = pm.sample(n_iter, init=None, njobs=n_jobs)
return BestResult(trace, model)
In [130]:
def summarize(best_result, kde=True, plot=True):
trace, model = best_result
if plot:
ax = pm.plot_posterior(trace[100:],
varnames=[r"group1_mean", r"group2_mean",
r"group1_std", "group2_std",
r"ν_minus_one"],
kde_plot=kde, color="C0");
if kde:
for a in (1, 3):
ax[a].lines[0].set_color("C1")
plt.figure()
pm.plot_posterior(trace[1000:],
varnames=["difference of means", "difference of stds",
"effect size"],
ref_val=0, kde_plot=True, color="C2");
plt.figure()
pm.forestplot(trace[1000:], varnames=[v.name for v in model.vars[:2]]);
plt.figure()
pm.forestplot(trace[1000:], varnames=[v.name for v in model.vars[2:]])
pm.summary(trace[1000:],
varnames=["difference of means", "difference of stds",
"effect size"])
In [138]:
def analyze_differences(df, columns, params, n_iter=2000, n_jobs=2,
show_summaries=True, plot=False):
traces = {}
for column, param in zip(columns, params):
sample1 = df[df.experiment_type==ExperimentType.Onboard][column]
sample2 = df[df.experiment_type==ExperimentType.Spirit][column]
best_result = best(sample1, sample2, *param,
n_iter=n_iter, n_jobs=n_jobs)
traces[column] = best_result
if show_summaries:
summarize(best_result, plot=plot)
In [143]:
analyze_differences(analyses, ["dist_err", "duration"], [[(0, 2), 0.5], [(5, 50), 50]])
Import the files.
In [488]:
ax1 = plt.subplot("121")
for filename in glob.glob("csv/experiment-1_*.csv"):
if "user-99" not in filename:
df = pd.read_csv(filename, parse_dates=["time"])
if any(df.arrived):
plot_xy_conditional(df, df.arrived==1, x="xn", y="yn", c="C0", c_condition="C0",
alpha_not_condition=0.2, alpha_condition=0.5, line=True,
zorder_condition=1, zorder_not_condition=0)
plot_targets(target_coords=[TARGET], show_final=False, zorder=-1)
plt.title("Onboard")
ax2 = plt.subplot("122", sharex=ax1, sharey=ax1)
for filename in glob.glob("csv/experiment-2_*.csv"):
if "user-99" not in filename:
df = pd.read_csv(filename, parse_dates=["time"])
if any(df.arrived):
plot_xy_conditional(df, df.arrived==1, x="xn", y="yn", c="C1", c_condition="C1",
alpha_not_condition=0.2, alpha_condition=0.5, line=True,
zorder_condition=1, zorder_not_condition=0)
plot_targets(target_coords=[TARGET], show_final=False, zorder=-1)
plt.title("SPIRIT")
Out[488]:
In [489]:
for filename in glob.glob("csv/experiment-1_*.csv"):
if "user-99" not in filename:
df = pd.read_csv(filename, parse_dates=["time"])
if any(df.arrived):
plot_xy_conditional(df, df.arrived==1, x="xn", y="yn", c="C0", c_condition="C0",
alpha_not_condition=0.2, alpha_condition=0.5, line=True,
zorder_condition=1, zorder_not_condition=0)
onboard_path, = plt.plot([], [], color="C0", label="Onboard path")
onboard_arrival, = plt.plot([], [], linestyle="none", color="C0", marker="o", label="Onboard arrival")
for filename in glob.glob("csv/experiment-2_*.csv"):
if "user-99" not in filename:
df = pd.read_csv(filename, parse_dates=["time"])
if any(df.arrived):
plot_xy_conditional(df, df.arrived==1, x="xn", y="yn", c="C1", c_condition="C1",
alpha_not_condition=0.2, alpha_condition=0.5, line=True,
zorder_condition=1, zorder_not_condition=0)
spirit_path, = plt.plot([], [], color="C1", label="SPIRIT path")
spirit_arrival, = plt.plot([], [], linestyle="none", color="C1", marker="o", label="SPIRIT arrival")
plot_targets(target_coords=[TARGET], show_final=False, zorder=-1)
plt.xlabel(r"$x$")
plt.ylabel(r"$y$")
plt.legend(handles=[onboard_path, onboard_arrival, spirit_path, spirit_arrival])
Out[489]:
Check not too many multiple arrivals.
In [96]:
filenames = list(usable_filenames())
filenames
Out[96]:
In [499]:
for filename in glob.glob("csv/experiment-*_user-08*.csv"):
df = pd.read_csv(filename, parse_dates=["time"])
plot_targets(target_coords=[TARGET], show_final=False, zorder=0, crosshair=True)
color = "C0" if filename[15]=="1" else "C1"
plot_xy_conditional(df, df.arrived==1, x="xn", y="yn", c=color, c_condition=color,
alpha_not_condition=0.5, alpha_condition=0.5, line=True)
In [40]:
analyses = analyze_all()
results = load_all()
In [217]:
results, analyses = load()
analyses.head()
In [ ]:
analyses["group"] = (analyses.user % 2).astype(int)
analyses["start"] = [ExperimentType(e % 2 + 1) for e in analyses.user]
analyses["experiment_int"] = [e.value for e in analyses.experiment_type]
analyses["experiment"] = [e.name for e in analyses.experiment_type]
analyses.experiment.replace("Spirit", "SPIRIT", inplace=True)
results["group"] = (results.user % 2).astype(int)
results["start"] = [ExperimentType(e % 2 + 1) for e in results.user]
results["experiment_int"] = [e.value for e in results.experiment_type]
results["experiment"] = [e.name for e in results.experiment_type]
results.experiment.replace("Spirit", "SPIRIT", inplace=True)
results["distance"] = distance(results, TARGET)
results["dx"] = results.xn - TARGET.x
results["dy"] = results.yn - TARGET.y
results["total_ordering"] = ((results.run.diff(1) != 0)
| (results.experiment_int.diff(1) != 0)
| (results.user.diff(1) != 0)).astype('int').cumsum() - 1
In [27]:
for user in set(analyses.user):
_df = analyses[analyses.user == user].sort_values(by="experiment_int", ascending=np.all(analyses[analyses.user==user].start==ExperimentType.Onboard))
_df["order"] = range(1, len(_df) + 1)
for idx in _df.index:
analyses.loc[idx, "order"] = int(_df.loc[idx, "order"])
results.loc[results.total_ordering==idx, "order"] = int(_df.loc[idx, "order"])
In [28]:
for col in ["user", "run", "group", "order"]:
analyses[col] = analyses[col].astype(int)
for col in ["arrived", "order"]:
results[col] = results[col].astype(int)
In [29]:
spirit_arrived = results[(results.arrived==1) & (results.experiment_type==ExperimentType.Spirit)]
onboard_arrived = results[(results.arrived==1) & (results.experiment_type==ExperimentType.Onboard)]
In [1160]:
plt.scatter(onboard_arrived.xn, onboard_arrived.yn, label="Onboard")
plt.scatter(spirit_arrived.xn, spirit_arrived.yn, label="SPIRIT")
plot_targets(show_start=False, show_final=False, target_coords=[TARGET])
plt.legend()
Out[1160]:
In [632]:
plt.scatter(spirit_arrived[spirit_arrived.start==ExperimentType.Onboard].xn,
spirit_arrived[spirit_arrived.start==ExperimentType.Onboard].yn,
c="C1", label="Group 0")
plt.scatter(spirit_arrived[spirit_arrived.start==ExperimentType.Spirit].xn,
spirit_arrived[spirit_arrived.start==ExperimentType.Spirit].yn,
c=shade_color("C1", -50), label="Group 1")
plot_targets(show_start=False, show_final=False, target_coords=[TARGET])
plt.title("SPIRIT")
plt.legend()
Out[632]:
In [633]:
plt.scatter(onboard_arrived[onboard_arrived.group==0].xn,
onboard_arrived[onboard_arrived.group==0].yn,
c=shade_color("C0", -50), label="Group 0")
plt.scatter(onboard_arrived[onboard_arrived.group==1].xn,
onboard_arrived[onboard_arrived.group==1].yn,
c="C0", label="Group 1")
plot_targets(show_start=False, show_final=False, target_coords=[TARGET])
plt.title("Onboard")
plt.legend()
Out[633]:
In [101]:
plt.scatter(spirit_arrived[spirit_arrived.order==1].xn, spirit_arrived[spirit_arrived.order==1].yn, label="Run 1", c=saturate_color("C1", -50))
plt.scatter(spirit_arrived[spirit_arrived.order==2].xn, spirit_arrived[spirit_arrived.order==2].yn, label="Run 2", c=saturate_color("C1", -25))
plt.scatter(spirit_arrived[spirit_arrived.order==3].xn, spirit_arrived[spirit_arrived.order==3].yn, label="Run 3", c=saturate_color("C1", 10))
plt.scatter(spirit_arrived[spirit_arrived.order==4].xn, spirit_arrived[spirit_arrived.order==4].yn, label="Run 4", c=saturate_color("C1", 50))
plot_targets(show_start=False, show_final=False, target_coords=[TARGET])
plt.title("SPIRIT")
plt.legend()
plt.axis("equal")
Out[101]:
In [640]:
plt.scatter(onboard_arrived[onboard_arrived.order==1].xn, onboard_arrived[onboard_arrived.order==1].yn, label="Run 1", c=shade_color("C0", -50))
plt.scatter(onboard_arrived[onboard_arrived.order==2].xn, onboard_arrived[onboard_arrived.order==2].yn, label="Run 2", c=shade_color("C0", -25))
plt.scatter(onboard_arrived[onboard_arrived.order==3].xn, onboard_arrived[onboard_arrived.order==3].yn, label="Run 3", c=shade_color("C0", 0))
plt.scatter(onboard_arrived[onboard_arrived.order==4].xn, onboard_arrived[onboard_arrived.order==4].yn, label="Run 4", c=shade_color("C0", 25))
plot_targets(show_start=False, show_final=False, target_coords=[TARGET])
plt.title("Onboard")
plt.legend()
Out[640]:
In [642]:
analyses[analyses.user == 6].sort_values
Out[642]:
In [643]:
analyses[analyses.group == 0].rms.mean()
Out[643]:
In [644]:
analyses[analyses.group == 1].rms.mean()
Out[644]:
In [645]:
analyses[analyses.experiment_type == ExperimentType.Spirit].dist_err.mean()
Out[645]:
In [646]:
analyses[analyses.experiment_type == ExperimentType.Onboard].rms.mean()
Out[646]:
In [647]:
analyses[(analyses.experiment_type == ExperimentType.Spirit) & (analyses.group == 0)].rms.mean()
Out[647]:
In [648]:
analyses[(analyses.experiment_type == ExperimentType.Spirit) & (analyses.group == 1)].rms.mean()
Out[648]:
In [649]:
analyses[(analyses.experiment_type == ExperimentType.Onboard) & (analyses.group == 0)].rms.mean()
Out[649]:
In [650]:
analyses[(analyses.experiment_type == ExperimentType.Onboard) & (analyses.group == 1)].rms.mean()
Out[650]:
In [651]:
plt.get_cmap("Dark2").colors
Out[651]:
In [652]:
dt=analyses.duration.iloc[0]
In [227]:
g = sns.factorplot(x="experiment", y="duration", data=analyses, hue="group",
size=6, aspect=.75, kind="box")
sns.swarmplot(x="experiment", y="duration", data=analyses, hue="group", split=True, palette="Set2")
plt.ylim(0, 80)
g.despine(left=True)
Out[227]:
In [655]:
g = sns.factorplot(x="experiment", y="duration", data=analyses, hue="group",
capsize=.2, size=6, aspect=.75, kind="bar")
g.despine(left=True)
Out[655]:
In [658]:
g = sns.factorplot(x="experiment", y="duration", data=analyses, hue="group",
capsize=.2, size=6, aspect=.75, kind="bar")
sns.swarmplot(x="experiment", y="duration", data=analyses, color="C5")
g.despine(left=True)
Out[658]:
In [659]:
g = sns.factorplot(x="experiment", y="rms", data=analyses, hue="group",
capsize=.2, size=6, aspect=.75, kind="bar")
g.despine(left=True)
Out[659]:
In [660]:
g = sns.factorplot(x="experiment", y="rms", data=analyses,
capsize=.2, size=6, aspect=.75, kind="bar")
g.despine(left=True)
Out[660]:
In [661]:
g = sns.factorplot(x="experiment", y="rms", col="group", data=analyses,
capsize=.2, size=6, aspect=.75)
g.despine(left=True)
Out[661]:
In [662]:
g = sns.factorplot(x="order", y="rms", col="group", hue="experiment", data=analyses,
capsize=.2, size=6, aspect=.75)
g.despine(left=True)
Out[662]:
In [663]:
g = sns.factorplot(x="order", y="rms", hue="experiment", data=analyses,
capsize=.2, size=6, aspect=.75, kind="bar")
g.despine(left=True)
Out[663]:
In [664]:
g = sns.factorplot(x="order", y="rms", hue="user", col="group", data=analyses,
capsize=.2, size=6, aspect=.75)
g.despine(left=True)
Out[664]:
In [666]:
g = sns.factorplot(x="order", y="rms", hue="experiment", data=analyses,
capsize=.2, size=6, aspect=.75)
g.despine(left=True)
Out[666]:
In [259]:
g = sns.factorplot(x="order", y="rms", hue="group", col="experiment", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[259]:
In [260]:
g = sns.factorplot(x="order", y="rms_x", col="group", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[260]:
In [261]:
g = sns.factorplot(x="order", y="rms_y", col="group", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[261]:
In [262]:
g = sns.factorplot(x="experiment", y="x_err", col="group", hue="user", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[262]:
In [263]:
g = sns.factorplot(x="experiment", y="rms_x", col="group", hue="user", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[263]:
In [264]:
g = sns.factorplot(x="order", y="rms", col="group", hue="user", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[264]:
In [270]:
g = sns.factorplot(x="order", y="rms_x", col="group", hue="user", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[270]:
In [271]:
g = sns.factorplot(x="experiment", y="rms", col="group", hue="user", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[271]:
In [1098]:
g = sns.factorplot(x="experiment", y="distance", col="group", data=results[results.arrived==1],
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[1098]:
In [273]:
g = sns.factorplot(x="experiment", y="distance", col="group", hue="user", data=results[results.arrived==1],
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[273]:
In [274]:
g = sns.factorplot(x="order", y="distance", col="group", hue="user", data=results[results.arrived==1],
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[274]:
In [85]:
g = sns.factorplot(x="order", y="xn", col="group", hue="user", data=results[results.arrived==1],
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
g.axes[0][0].axhline(0)
g.axes[0][1].axhline(0)
Out[85]:
In [276]:
g = sns.factorplot(x="order", y="yn", col="group", hue="user", data=results[results.arrived==1],
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
g.axes[0][0].axhline(6)
g.axes[0][1].axhline(6)
Out[276]:
In [277]:
g = sns.factorplot(x="order", y="rms", col="group", hue="user", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[277]:
In [278]:
g = sns.factorplot(x="order", y="rms", hue="experiment", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[278]:
In [279]:
g = sns.factorplot(x="order", y="rms", hue="experiment", data=analyses,
capsize=.2, palette="Dark2", size=6, aspect=.75, kind="bar")
g.despine(left=True)
Out[279]:
In [280]:
g = sns.factorplot(x="experiment", y="yn", col="group", hue="user", data=results[results.arrived==1],
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
g.axes[0][0].axhline(6)
g.axes[0][1].axhline(6)
Out[280]:
In [281]:
g = sns.factorplot(x="experiment", y="xn", col="group", hue="user", data=results[results.arrived==1],
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
g.axes[0][0].axhline(0)
g.axes[0][1].axhline(0)
Out[281]:
In [282]:
g = sns.PairGrid(analyses, y_vars="rms_x",
x_vars=["order", "experiment", "group"],
size=5, aspect=.5)
# Draw a seaborn pointplot onto each Axes
g.map(sns.pointplot, color=sns.xkcd_rgb["plum"])
g.set(ylim=(0, 1))
sns.despine(fig=g.fig, left=True)
In [283]:
g = sns.PairGrid(analyses, y_vars="rms_y",
x_vars=["order", "experiment", "group"],
size=5, aspect=.5)
# Draw a seaborn pointplot onto each Axes
g.map(sns.pointplot, color=sns.xkcd_rgb["plum"])
g.set(ylim=(0, 1))
sns.despine(fig=g.fig, left=True)
In [1029]:
g = sns.PairGrid(analyses, y_vars="rms",
x_vars=["order", "experiment", "group"],
size=5, aspect=.5)
# Draw a seaborn pointplot onto each Axes
g.map(sns.pointplot)
g.set(ylim=(0, 1))
sns.despine(fig=g.fig, left=True)
In [64]:
sns.lmplot(x="xn", y="yn", col="group", hue="experiment", data=results[results.arrived==1],
col_wrap=2, palette="Dark2",
scatter_kws={"s": 50, "alpha": 1})
Out[64]:
In [65]:
sns.lmplot(x="xn", y="yn", col="experiment", hue="group", data=results[results.arrived==1],
col_wrap=2, palette="Dark2",
scatter_kws={"s": 50, "alpha": 1})
Out[65]:
In [414]:
sns.distplot(analyses[analyses.experiment_type==ExperimentType.Onboard].duration, hist=False)
sns.distplot(analyses[analyses.experiment_type==ExperimentType.Spirit].duration, hist=False)
Out[414]:
In [788]:
g = sns.jointplot(spirit_arrived.xn, spirit_arrived.yn, kind="kde", size=7, space=0, color="C1")
In [66]:
g = sns.jointplot(spirit_arrived.xn, spirit_arrived.yn, kind="kde", size=7, space=0)
plt.title("SPIRIT")
g = sns.jointplot(spirit_arrived[spirit_arrived.group==0].xn, spirit_arrived[spirit_arrived.group==0].yn, kind="kde", size=7, space=0)
plt.title("SPIRIT - Group 0")
g = sns.jointplot(spirit_arrived[spirit_arrived.group==1].xn, spirit_arrived[spirit_arrived.group==1].yn, kind="kde", size=7, space=0)
plt.title("SPIRIT - Group 1")
Out[66]:
In [67]:
g = sns.jointplot(onboard_arrived.xn, onboard_arrived.yn, kind="kde", size=7, space=0)
g = sns.jointplot(onboard_arrived[onboard_arrived.group==0].xn, onboard_arrived[onboard_arrived.group==0].yn, kind="kde", size=7, space=0)
g = sns.jointplot(onboard_arrived[onboard_arrived.group==1].xn, onboard_arrived[onboard_arrived.group==1].yn, kind="kde", size=7, space=0)
In [27]:
g = sns.jointplot(results[results.arrived==1].xn, results[results.arrived==1].yn, kind="kde", size=7, space=0)
# g.plot_marginals(sns.rugplot, height=0.1
In [193]:
analyses["experiment_int"] = [e.value for e in analyses.experiment]
results["experiment_int"] = [e.value for e in results.experiment]
In [185]:
g = sns.factorplot(x="experiment", y="rms", hue="group", data=analyses,
size=6, kind="bar", palette="Dark2")
g.despine(left=True)
Out[185]:
In [186]:
g = sns.factorplot(x="order", y="rms", hue="group", data=analyses,
size=6, kind="bar", palette="Dark2")
g.despine(left=True)
Out[186]:
In [187]:
g = sns.factorplot(x="order", y="rms", hue="experiment", col="group", data=analyses,
size=6, kind="bar", palette="Dark2")
g.despine(left=True)
Out[187]:
In [1030]:
g = sns.FacetGrid(analyses, col="experiment", margin_titles=True)
bins = np.linspace(0, 2.5, 13)
g.map(plt.hist, "rms", bins=bins, lw=0)
Out[1030]:
In [1186]:
sns.distplot(analyses[analyses.experiment_type == ExperimentType.Spirit].duration, hist=False, rug=True, color="C1")
sns.distplot(analyses[analyses.experiment_type == ExperimentType.Onboard].duration, hist=False, rug=True, color="C0")
Out[1186]:
In [1187]:
sns.distplot(analyses[analyses.experiment_type == ExperimentType.Spirit].rms, hist=False, rug=True, color="C0")
sns.distplot(analyses[analyses.experiment_type == ExperimentType.Onboard].rms, hist=False, rug=True, color="C1")
Out[1187]:
In [291]:
analyses[analyses.experiment_type == ExperimentType.Spirit].rms.mean()
Out[291]:
In [292]:
analyses[analyses.experiment_type == ExperimentType.Onboard].rms.mean()
Out[292]:
In [68]:
f, axes = plt.subplots(1, 2, figsize=(8, 8), sharex=True, sharey=True)
axes[0].set_aspect("equal")
axes[1].set_aspect("equal")
sns.kdeplot(onboard_arrived[onboard_arrived.group==0].xn, onboard_arrived[onboard_arrived.group==0].yn,
cmap="Reds", shade=True, shade_lowest=False, ax=axes[0])
sns.kdeplot(onboard_arrived[onboard_arrived.group==1].xn, onboard_arrived[onboard_arrived.group==1].yn,
cmap="Blues", shade=True, shade_lowest=False, ax=axes[0])
axes[0].scatter(0, 6, c="C7", s=100)
sns.kdeplot(spirit_arrived[spirit_arrived.group==1].xn, spirit_arrived[spirit_arrived.group==1].yn,
cmap="Blues", shade=True, shade_lowest=False, ax=axes[1])
sns.kdeplot(spirit_arrived[spirit_arrived.group==0].xn, spirit_arrived[spirit_arrived.group==0].yn,
cmap="Reds", shade=True, shade_lowest=False, ax=axes[1])
axes[1].scatter(0, 6, c="C7", s=100)
Out[68]:
In [84]:
g = sns.PairGrid(analyses[analyses.experiment_type==ExperimentType.Onboard][["rms", "rms_x", "rms_y"]], diag_sharey=False)
g.map_lower(sns.kdeplot, cmap="Blues_d")
g.map_upper(plt.scatter)
g.map_diag(sns.kdeplot, lw=3)
Out[84]:
In [38]:
g = sns.PairGrid(analyses[analyses.experiment_type==ExperimentType.Spirit][["rms", "rms_x", "rms_y"]], diag_sharey=False)
g.map_lower(sns.kdeplot)
g.map_upper(plt.scatter)
g.map_diag(sns.kdeplot, lw=3)
Out[38]:
In [40]:
g = sns.PairGrid(analyses[analyses.experiment_type==ExperimentType.Spirit][["dist_err", r"x_err", r"y_err"]], diag_sharey=False)
g.map_lower(sns.kdeplot)
g.map_upper(plt.scatter)
g.map_diag(sns.kdeplot, lw=3)
Out[40]:
In [196]:
g = sns.PairGrid(analyses[["rms", "rms_x", "rms_y"]], diag_sharey=False)
g.map_lower(sns.kdeplot, cmap="Blues_d")
g.map_upper(plt.scatter)
g.map_diag(sns.kdeplot, lw=3)
Out[196]:
In [195]:
g = sns.PairGrid(analyses[["rms", "rms_x", "rms_y", "group", "order", "experiment_int"]], diag_sharey=False)
g.map_lower(sns.kdeplot, cmap="Blues_d")
g.map_upper(plt.scatter)
g.map_diag(sns.kdeplot, lw=3)
Out[195]:
In [70]:
g = sns.PairGrid(results[results.arrived==1][["xn", "yn", "group", "order", "experiment_int"]], diag_sharey=False)
g.map_lower(sns.kdeplot, cmap="Blues_d")
g.map_upper(plt.scatter)
g.map_diag(sns.kdeplot, lw=3)
Out[70]:
In [746]:
sns.pairplot(analyses[["rms", "rms_x", "rms_y", "group", "order", "experiment"]], hue="experiment")
Out[746]:
In [72]:
sns.pairplot(analyses[["rms", "rms_x", "rms_y", "group", "order", "experiment"]], hue="group")
Out[72]:
In [73]:
sns.pairplot(results[results.arrived==1][["xn", "yn", "group", "order", "experiment_int"]], hue="group")
Out[73]:
In [74]:
sns.pairplot(results[results.arrived==1][["xn", "yn", "group", "order", "experiment_int"]], hue="experiment_int")
Out[74]:
In [75]:
sns.swarmplot(x="group", y="rms", hue="experiment", data=analyses)
Out[75]:
In [171]:
import pickle
In [172]:
with open("data.pickle", "rb") as fin:
data = pickle.load(fin)
In [173]:
users = pd.DataFrame({"user_id": user.id_, "name": user.name, "age": user.age,
"teleop": user.teleop, "flying": user.flying} for user in data)
users
Out[173]:
In [174]:
users.age.astype(int).std()
Out[174]:
In [175]:
users.age.astype(int).mean()
Out[175]:
In [ ]:
In [179]:
_tlx_data = []
for user in data:
for experiment in user.experiments:
d = {"user": user.id_, "experiment_type": experiment.type_}
for component in experiment.tlx.components.values():
parsed = parse_tlx_component(component)
d[parsed.code] = parsed.score
_tlx_data.append(d)
tlx = pd.DataFrame(_tlx_data)
tlx["group"] = tlx.user % 2
tlx["tlx"] = tlx.mental + tlx.physical + tlx.temporal + tlx.performance + tlx.effort + tlx.frustration
tlx["order"] = [1, 2]*(len(tlx)//2)
tlx["experiment_int"] = [e.value for e in tlx.experiment_type]
tlx["experiment"] = [e.name for e in tlx.experiment_type]
tlx.experiment.replace("Spirit", "SPIRIT", inplace=True)
tlx
Out[179]:
In [180]:
_survey_data = []
for user in data:
for experiment in user.experiments:
d = {"user": user.id_, "experiment_type": experiment.type_}
d.update({i.code:i.score for i in experiment.survey.questions.values()})
_survey_data.append(d)
surveys = pd.DataFrame(_survey_data)
surveys["group"] = tlx.user % 2
surveys["order"] = [1, 2]*(len(surveys)//2)
surveys["experiment"] = [e.name for e in surveys.experiment_type]
surveys["experiment_int"] = [e.value for e in surveys.experiment_type]
surveys.experiment.replace("Spirit", "SPIRIT", inplace=True)
surveys
Out[180]:
In [31]:
g = sns.factorplot(x="experiment", y="tlx", data=tlx,
size=6, kind="violin", split=True, inner=None)
sns.swarmplot(x="group", y="tlx", data=tlx, color="w", alpha=.5)
g.despine(left=True)
Out[31]:
In [46]:
g = sns.factorplot(x="experiment", y="tlx", data=tlx,
size=6, kind="bar")
In [47]:
g = sns.factorplot(x="experiment", y="tlx", data=tlx,
size=6, kind="box")
plt.ylim(0, plt.ylim()[1])
Out[47]:
In [48]:
g = sns.factorplot(x="variable", y="value", hue="experiment",
data=pd.melt(tlx, id_vars=["user", "experiment", "group", "tlx", "order"]),
size=6, kind="bar", palette="Dark2")
g.despine(left=True)
In [49]:
g = sns.factorplot(x="group", y="tlx", hue="experiment", data=tlx,
size=6, kind="bar", palette="Dark2")
g.despine(left=True)
Out[49]:
In [97]:
g = sns.factorplot(x="experiment", y="tlx", hue="group", data=tlx,
size=6, kind="bar", palette="Dark2")
g.despine(left=True)
Out[97]:
In [98]:
g = sns.PairGrid(tlx, y_vars="tlx",
x_vars=["group", "experiment"],
size=5, aspect=.5)
# Draw a seaborn pointplot onto each Axes
g.map(sns.pointplot, color=sns.xkcd_rgb["plum"])
sns.despine(fig=g.fig, left=True)
In [99]:
g = sns.factorplot(x="experiment", y="tlx", col="group", hue="user", data=tlx,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[99]:
In [100]:
g = sns.factorplot(x="experiment", y="tlx", col="group", data=tlx,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[100]:
In [101]:
g = sns.factorplot(x="group", y="tlx", col="experiment", data=tlx,
size=6, kind="bar", palette="Dark2")
g.despine(left=True)
Out[101]:
In [102]:
g = sns.factorplot(x="group", y="tlx", col="experiment", data=tlx,
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[102]:
In [103]:
g = sns.factorplot(x="experiment", y="value", col="group", hue="variable",
data=pd.melt(tlx, id_vars=["user", "experiment", "group", "tlx", "order"]),
capsize=.2, palette="Dark2", size=6, aspect=.75)
g.despine(left=True)
Out[103]:
In [104]:
g = sns.factorplot(x="variable", y="value", hue="experiment", col="group",
data=pd.melt(tlx, id_vars=["user", "experiment", "group", "tlx", "order"]),
size=6, kind="bar", palette="Dark2")
g.despine(left=True)
Out[104]:
In [105]:
surveys
Out[105]:
In [106]:
g = sns.factorplot(x="variable", y="value", hue="experiment",
data=pd.melt(surveys, id_vars=["user", "experiment", "group", "order"]),
size=6, kind="bar", palette="Dark2")
g.set_xticklabels(rotation=90)
g.despine(left=True)
Out[106]:
In [107]:
g = sns.factorplot(x="variable", y="value", hue="experiment", col="group",
data=pd.melt(surveys, id_vars=["user", "experiment", "group", "order"]),
size=6, kind="bar", palette="Dark2")
g.set_xticklabels(rotation=90)
g.despine(left=True)
Out[107]:
In [108]:
g = sns.factorplot(x="variable", y="value", hue="experiment", col="group",
data=pd.melt(surveys, id_vars=["user", "experiment", "group", "order"]),
size=6, kind="violin", split=True)
g.set_xticklabels(rotation=90)
g.despine(left=True)
Out[108]:
In [ ]:
In [142]:
sample1 = analyses[analyses.experiment_type==ExperimentType.Onboard].dist_err
sample2 = analyses[analyses.experiment_type==ExperimentType.Spirit].dist_err
trace_dist, model_dist = best(sample1, sample2, (0, 2), 0.5)
summarize(trace_dist, model_dist)
In [59]:
sample1 = analyses[analyses.experiment_type==ExperimentType.Onboard].x_err
sample2 = analyses[analyses.experiment_type==ExperimentType.Spirit].x_err
trace_x, model_x = best(sample1, sample2, (0, 2), 0.5)
summarize(trace_x, model_x)
In [61]:
sample1 = analyses[analyses.experiment_type==ExperimentType.Onboard].y_err
sample2 = analyses[analyses.experiment_type==ExperimentType.Spirit].y_err
trace_y, model_y = best(sample1, sample2, (0, 2), 0.5)
summarize(trace_y, model_y)
In [62]:
sample1 = analyses[analyses.experiment_type==ExperimentType.Onboard].rms_x
sample2 = analyses[analyses.experiment_type==ExperimentType.Spirit].rms_x
trace_rmsx, model_rmsx = best(sample1, sample2, (0, 2), 0.5)
summarize(trace_rmsx, model_rmsx)
In [70]:
sample1 = analyses[analyses.experiment_type==ExperimentType.Onboard].rms_y
sample2 = analyses[analyses.experiment_type==ExperimentType.Spirit].rms_y
trace_rmsy, model_rmsy = best(sample1, sample2, (0, 2), 0.5)
summarize(trace_rmsy, model_rmsy)
In [65]:
sample1 = analyses[analyses.experiment_type==ExperimentType.Onboard].duration
sample2 = analyses[analyses.experiment_type==ExperimentType.Spirit].duration
trace_dur, model_dur = best(sample1, sample2, (5, 50), 50)
summarize(trace_dur, model_dur)
In [212]:
ax1 = plt.subplot("121")
plot_overview(results, ExperimentType.Onboard, color="C0")
ax2 = plt.subplot("122", sharex=ax1, sharey=ax1)
plot_overview(results, ExperimentType.Spirit, color="C1", ylabel="")
plt.setp(ax2.get_yticklabels(), visible=False);
In [ ]:
In [213]:
ax1 = plt.subplot("121")
plot_detailed(results, ExperimentType.Onboard, color="C0", crosshair=True)
ax2 = plt.subplot("122", sharex=ax1, sharey=ax1)
plot_detailed(results, ExperimentType.Spirit, color="C1", crosshair=True, ylabel="")
plt.setp(ax2.get_yticklabels(), visible=False);
In [214]:
plot_distribution(results, ExperimentType.Onboard, color="C0", crosshair=True)
plot_distribution(results, ExperimentType.Spirit, color="C1", crosshair=True)
In [38]:
# plot_distribution(results[results.group==0], ExperimentType.Onboard, color="C0", crosshair=True)
# plot_distribution(results[results.group==0], ExperimentType.Spirit, color="C1", crosshair=True)
In [39]:
# plot_distribution(results[results.group==1], ExperimentType.Onboard, color="C0", crosshair=True)
# plot_distribution(results[results.group==1], ExperimentType.Spirit, color="C1", crosshair=True)
In [255]:
g = sns.boxplot(x="experiment", y="duration", data=analyses)
sns.swarmplot(x="experiment", y="duration", split=True, data=analyses, palette="Set2")
plt.ylim(0, plt.ylim()[1])
plt.ylabel("duration (s)")
plt.title("Duration")
Out[255]:
In [154]:
g = sns.factorplot(x="order", y="duration", hue="experiment", data=analyses, capsize=0.2)
plt.title("Duration")
plt.ylabel("duration (s)")
plt.xlabel("run")
plt.ylim(0, plt.ylim()[1])
Out[154]:
In [165]:
molten = pd.melt(analysis, id_vars=["user", "experiment", "order", "group"],
value_vars=["path_length", "move_x", "move_y"])
g = sns.factorplot(x="order", y="value", col="variable",
data=molten, hue="experiment",
size=4)
g.fig.axes[0].set_title("Path length")
g.fig.axes[1].set_title("Movement in $x$")
g.fig.axes[2].set_title("Movement in $y$")
g.fig.axes[0].set_ylabel("distance (m)")
plt.ylim(0, plt.ylim()[1])
Out[165]:
In [150]:
molten = pd.melt(analysis, id_vars=["user", "experiment", "order", "group"],
value_vars=["path_length", "move_x", "move_y"])
g = sns.factorplot(x="experiment", y="value", col="variable",
data=molten,
kind="box", size=4)
g.fig.axes[0].set_title("Path length")
g.fig.axes[1].set_title("Movement in $x$")
g.fig.axes[2].set_title("Movement in $y$")
g.fig.axes[0].set_ylabel("distance (m)")
plt.ylim(0, plt.ylim()[1])
Out[150]:
In [157]:
molten = pd.melt(analysis, id_vars=["user", "experiment", "order", "group"],
value_vars=["move_l", "move_r", "move_x"])
g = sns.factorplot(x="experiment", y="value", col="variable",
data=molten,
kind="box", size=4)
g.fig.axes[0].set_title("Movement to the left")
g.fig.axes[1].set_title("Movement to the right")
g.fig.axes[2].set_title("Movement in $x$")
g.fig.axes[0].set_ylabel("distance (m)")
plt.ylim(0, plt.ylim()[1])
Out[157]:
In [162]:
sns.boxplot(x="experiment", y="move_b", data=analyses)
sns.swarmplot(x="experiment", y="move_b", split=True, data=analyses, palette="Set2")
plt.ylabel("distance (m)")
plt.title("Movement backwards")
Out[162]:
In [169]:
sns.factorplot(x="experiment", y="move_b", data=analyses, kind="box", size=2.1)
sns.swarmplot(x="experiment", y="move_b", split=True, data=analyses, palette="Set2")
plt.ylabel("distance (m)")
plt.title("Movement backwards")
Out[169]:
In [154]:
molten = pd.melt(analyses, id_vars=["user", "experiment", "order", "group"],
value_vars=["move_b", "move_f", "move_y"])
g = sns.factorplot(x="experiment", y="value", col="variable",
data=molten,
kind="box", size=4)
g.fig.axes[0].set_title("Movement backwards")
g.fig.axes[1].set_title("Movement forwards")
g.fig.axes[2].set_title("Movement in $y$")
g.fig.axes[0].set_ylabel("distance (m)")
plt.ylim(0, plt.ylim()[1])
Out[154]:
In [257]:
molten = pd.melt(analyses, id_vars=["user", "experiment", "order", "group"],
value_vars=["rms", "rms_x", "rms_y"])
g = sns.factorplot(x="experiment", y="value", col="variable",
data=molten,
kind="box", size=4)
g.fig.axes[0].set_title("RMS Error")
g.fig.axes[1].set_title("RMS Error in $x$")
g.fig.axes[2].set_title("RMS Error in $y$")
g.fig.axes[0].set_ylabel("error (m)")
Out[257]:
In [167]:
sns.boxplot?
In [43]:
g = sns.factorplot(x="order", y="value", hue="experiment", col="variable",
data=pd.melt(analyses, id_vars=["user", "experiment", "order", "group"],
value_vars=["rms", "rms_x", "rms_y"]),
capsize=0.2)
g.fig.axes[0].set_title("RMS Error")
g.fig.axes[1].set_title("RMS Error in $x$")
g.fig.axes[2].set_title("RMS Error in $y$")
g.fig.axes[0].set_ylabel("error (m)")j
g.fig.axes[0].set_xlabel("run")
g.fig.axes[1].set_xlabel("run")
g.fig.axes[2].set_xlabel("run")
Out[43]:
In [44]:
g = sns.factorplot(x="experiment", y="value", col="variable",
data=pd.melt(analyses, id_vars=["user", "experiment", "order", "group"],
value_vars=[r"dist_err", r"x_err", r"y_err"]),
size=4, kind="box")
g.fig.axes[0].set_title("Distance from target")
g.fig.axes[1].set_title("Distance from target in $x$")
g.fig.axes[2].set_title("Distance from target in $y$")
g.fig.axes[0].set_ylabel("distance (m)")
g.axes[0][0].axhline(0, color="black", linewidth=1, zorder=-1)
g.axes[0][1].axhline(0, color="black", linewidth=1, zorder=-1)
g.axes[0][2].axhline(0, color="black", linewidth=1, zorder=-1)
Out[44]:
In [228]:
g = sns.boxplot(x="experiment", y="tlx", data=tlx)
plt.ylim(0, plt.ylim()[1])
plt.title("NASA-TLX results")
plt.ylabel("weighted score")
sns.swarmplot(x="experiment", y=r"tlx", data=tlx, palette="Set2", split=True)
Out[228]:
In [252]:
molten = pd.melt(tlx, id_vars=["user", "experiment", "order"],
value_vars=["mental", "physical", "temporal",
"performance", "effort", "frustration"],
var_name="component", value_name="score")
g = sns.barplot(x=r"component", y="score", hue="experiment",
data=molten, palette="Dark2")
sns.swarmplot(x="component", y=r"score", data=molten, hue="experiment", split=True, palette="Set2")
handles, labels = g.get_legend_handles_labels()
plt.legend(handles[2:], labels[2:])
plt.ylabel("component score")
plt.title("NASA-TLX component analysis")
Out[252]:
In [193]:
molten = pd.melt(surveys, id_vars=["user", "experiment", "order"],
value_vars=[r"orientation_understanding", r"orientation_control",
r"position_understanding", r"position_control",
r"spacial_understanding", r"spacial_control"],
var_name="question", value_name="rating")
g = sns.factorplot(x=r"rating", y=r"question", hue="experiment",
data=molten, kind="bar", size=7)
g = sns.swarmplot(x="rating", y=r"question", data=molten, hue="experiment", split=True, palette="Set2")
plt.gca().set_yticklabels(["orientation understanding", "orientation control",
"absolute position understanding", "absolute positional control",
"relative position understanding", "relative position control"]);
# g.legend_.set_visible(False)
plt.xlabel("rating")
plt.title("Survey results")
Out[193]:
In [183]:
g.ax.legend_.set_visible
Out[183]:
In [66]:
pm.plot_posterior(trace_dist[1000:],
varnames=[r'difference of means', "effect size"],
ref_val=0,
kde_plot=True)
plt.gcf().suptitle("Distance")
Out[66]:
In [69]:
pm.plot_posterior(trace_rmsx[1000:],
varnames=[r'difference of means', "effect size"],
ref_val=0,
kde_plot=True)
plt.gcf().suptitle("Distance in $x$")
Out[69]:
In [71]:
pm.plot_posterior(trace_rmsy[1000:],
varnames=[r'difference of means', "effect size"],
ref_val=0,
kde_plot=True)
plt.gcf().suptitle("Distance in $y$")
Out[71]:
In [68]:
pm.plot_posterior(trace_dur[1000:],
varnames=[r'difference of means', "effect size"],
ref_val=0,
kde_plot=True)
plt.gcf().suptitle("Duration")
Out[68]:
In [192]:
pd.read_csv("foo.csv")
In [72]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard)].duration
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit)].duration
stats.ttest_rel(sample1, sample2)
Out[72]:
In [73]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==0)].duration
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==0)].duration
stats.ttest_rel(sample1, sample2)
Out[73]:
In [74]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==1)].duration
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==1)].duration
stats.ttest_rel(sample1, sample2)
Out[74]:
In [75]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard)].dist_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit)].dist_err
stats.ttest_rel(sample1, sample2)
Out[75]:
In [76]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==0)].dist_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==0)].dist_err
stats.ttest_rel(sample1, sample2)
Out[76]:
In [77]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==1)].dist_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==1)].dist_err
stats.ttest_rel(sample1, sample2)
Out[77]:
In [78]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard)].x_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit)].x_err
stats.ttest_rel(sample1, sample2)
Out[78]:
In [79]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==0)].x_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==0)].x_err
stats.ttest_rel(sample1, sample2)
Out[79]:
In [80]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==1)].x_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==1)].x_err
stats.ttest_rel(sample1, sample2)
Out[80]:
In [81]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard)].rms_x
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit)].rms_x
stats.ttest_rel(sample1, sample2)
Out[81]:
In [82]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==0)].rms_x
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==0)].rms_x
stats.ttest_rel(sample1, sample2)
Out[82]:
In [83]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==1)].rms_x
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==1)].rms_x
stats.ttest_rel(sample1, sample2)
Out[83]:
In [84]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard)].y_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit)].y_err
stats.ttest_rel(sample1, sample2)
Out[84]:
In [85]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==0)].y_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==0)].y_err
stats.ttest_rel(sample1, sample2)
Out[85]:
In [86]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==1)].y_err
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==1)].y_err
stats.ttest_rel(sample1, sample2)
Out[86]:
In [87]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard)].rms_y
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit)].rms_y
stats.ttest_rel(sample1, sample2)
Out[87]:
In [88]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==0)].rms_y
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==0)].rms_y
stats.ttest_rel(sample1, sample2)
Out[88]:
In [89]:
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==1)].rms_y
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==1)].rms_y
stats.ttest_rel(sample1, sample2)
Out[89]:
In [190]:
def dnorm(x, mu, sd):
return 1/(sd * np.sqrt(2 * np.pi)) * np.exp(-(x - mu)**2 / (2 * sd**2))
def dexp(x, l):
return l * np.exp(- l*x)
def likelihood(parameters):
mu1, sd1, mu2, sd2 = parameters
return dnorm(sample1, mu1, sd1).prod()*dnorm(sample2, mu2, sd2).prod()
def prior(pooled, parameters):
mu1, sd1, mu2, sd2 = parameters
return (dnorm(mu1, pooled.mean(), 1000*pooled.std())
* dnorm(mu2, pooled.mean(), 1000*pooled.std())
* dexp(sd1, 0.1)
* dexp(sd2, 0.1))
def posterior(pooled, parameters):
return likelihood(parameters)*prior(pooled, parameters)
def mcmc(pooled, parameters, n_iter=10000):
results = np.zeros([niter, 4])
results[1,:] = parameters
for iteration in np.arange(2, niter):
candidate = parameters + np.random.normal(0, 0.5, 4)
ratio = posterior(pooled, candidate) / posterior(pooled, parameters)
if np.random.uniform() < ratio:
parameters = candidate
results[iteration, :] = parameters
#burn-in
results = results[499:niter-1, :]
return results
def best(sample1, sample2, params=None, n_iter=10000):
if params is None:
params = np.array([100, 10, 100, 10])
pooled = np.append(sample1, sample2)
results = mcmc(pooled, params, n_iter=n_iter)
mu1 = results[:, 1]
mu2 = results[:, 3]
return mu2 - mu1
In [191]:
sample1 = analyses[analyses.experiment_type==ExperimentType.Onboard].duration
sample2 = analyses[analyses.experiment_type==ExperimentType.Spirit].duration
sns.distplot(sample1, hist=False)
sns.distplot(sample2, hist=False)
Out[191]:
In [163]:
d = best(sample1, sample2, n_iter=1000)
sns.distplot(d)
plt.title(np.mean(d > 0))
Out[163]:
In [178]:
sample1 = analyses[analyses.experiment_type==ExperimentType.Onboard].dist_err
sample2 = analyses[analyses.experiment_type==ExperimentType.Spirit].dist_err
sns.distplot(sample1, hist=False, rug=True)
sns.distplot(sample2, hist=False, rug=True)
Out[178]:
In [192]:
d = best(sample1, sample2, n_iter=10000)
sns.distplot(d)
plt.title(np.mean(d > 0))
Out[192]:
In [217]:
def dnorm(x, mu, sig):
return 1/(sig * np.sqrt(2 * np.pi)) * np.exp(-(x - mu)**2 / (2 * sig**2))
def dexp(x, l):
return l * np.exp(- l*x)
def like(parameters):
[mu1, sig1, mu2, sig2] = parameters
return dnorm(sample1, mu1, sig1).prod()*dnorm(sample2, mu2, sig2).prod()
def prior(parameters):
[mu1, sig1, mu2, sig2] = parameters
return dnorm(mu1, pooled.mean(), 1000*pooled.std()) * dnorm(mu2, pooled.mean(), 1000*pooled.std()) * dexp(sig1, 0.1) * dexp(sig2, 0.1)
def posterior(parameters):
[mu1, sig1, mu2, sig2] = parameters
return like([mu1, sig1, mu2, sig2])*prior([mu1, sig1, mu2, sig2])
#create samples
np.random.seed=7
#sample1 = np.random.normal(100, 3, 8)
#sample2 = np.random.normal(97, 3, 10)
sample1 = analyses[(analyses.experiment_type==ExperimentType.Onboard) & (analyses.group==0)].rms
sample2 = analyses[(analyses.experiment_type==ExperimentType.Spirit) & (analyses.group==0)].rms
pooled= np.append(sample1, sample2)
sns.distplot(sample1, hist=False, rug=True)
sns.distplot(sample2, hist=False, rug=True)
mu1 = 1
sig1 = 0.1
mu2 = 1
sig2 = 0.1
parameters = np.array([mu1, sig1, mu2, sig2])
niter = 10000
results = np.zeros([niter, 4])
results[1,:] = parameters
for iteration in np.arange(2,niter):
candidate = parameters + np.random.normal(0,0.5,4)
ratio = posterior(candidate)/posterior(parameters)
if np.random.uniform() < ratio:
parameters = candidate
results[iteration,:] = parameters
#burn-in
results = results[499:niter-1,:]
mu1 = results[:,1]
mu2 = results[:,3]
d = (mu1 - mu2)
p_value = np.mean(mu1 < mu2)
plt.figure()
sns.distplot(d)
plt.title(p_value)
Out[217]:
In [ ]:
In [ ]: