Skip to content

Commit

Permalink
Merge pull request #60 from duembgen/new_results
Browse files Browse the repository at this point in the history
Add new results
  • Loading branch information
duembgen authored Dec 23, 2019
2 parents c72e869 + b116444 commit abf5862
Show file tree
Hide file tree
Showing 35 changed files with 1,856 additions and 879 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ install:
python:
- "3.6"
script:
- ./scripts/download_datasets Plaza2
- ./scripts/download_datasets all
- ./scripts/run_important_notebooks
- pytest test/
- make html
93 changes: 33 additions & 60 deletions GenerateAllFigures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -249,54 +249,16 @@
"source": [
"from scipy.io import loadmat\n",
"from trajectory_creator import get_trajectory\n",
"from public_data_utils import read_dataset, get_plotting_params\n",
"\n",
"plt.rcParams['figure.figsize'] = 7, 3\n",
"\n",
"verbose = False\n",
"anchor_names = None # use all anchors by default.\n",
"filename = 'datasets/Plaza2.mat' # triangle. works well.\n",
"\n",
"verbose = False\n",
"traj = get_trajectory(filename)\n",
"dataname = filename.split('/')[-1].split('.')[0]\n",
"\n",
"t_window = 0.1\n",
"eps = 0.2\n",
"xlim = -80, 10\n",
"ylim = -20, 75\n",
"\n",
"min_time = 45.1\n",
"period = 101 - 45\n",
"print('period:', period)\n",
"num_loops = 2\n",
"max_time = min_time + num_loops * period\n",
"traj.period = period\n",
"\n",
"#anchor_names = ['Range {}'.format(i) for i in range(1, 4)]\n",
"try:\n",
" result_dict = loadmat(filename)\n",
"except FileNotFoundError:\n",
" raise FileNotFoundError('Could not find {}. Did you run the script download_datasets?'.format(dataset))\n",
"except Exception as e:\n",
" print('Unknown reading error with {}. Check if the file looks ok.'.format(filename))\n",
" raise e\n",
"print('Successfully read {}'.format(filename))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from data_utils import prepare_dataset, range_system_id, gt_system_id\n",
"from evaluate_dataset import compute_distance_matrix\n",
"\n",
"full_df, anchors_df = prepare_dataset(\n",
" result_dict, \n",
" range_system_id, \n",
" gt_system_id, \n",
" [min_time, max_time], \n",
" t_window)"
"full_df, anchors_df, traj = read_dataset(filename)\n",
"xlim, ylim = get_plotting_params(filename)"
]
},
{
Expand All @@ -305,21 +267,18 @@
"metadata": {},
"outputs": [],
"source": [
"from data_utils import get_ground_truth\n",
"from public_data_utils import get_ground_truth\n",
"from evaluate_dataset import compute_distance_matrix, compute_anchors\n",
"chosen_df = full_df\n",
"chosen_distance = 'distance'\n",
"range_system_id = 'Range'\n",
"#chosen_distance = 'distance_gt'\n",
"\n",
"## Construct anchors. \n",
"if anchor_names is None:\n",
" anchors = anchors_df.loc[:, ['px', 'py', 'pz']].values.astype(np.float32).T\n",
"else:\n",
" anchors_df = anchors_df.loc[anchors_df.anchor_name.isin(anchor_names)]\n",
" anchors = get_coordinates(anchors_df, anchor_names)\n",
"anchors = compute_anchors(anchors_df, anchor_names)\n",
"\n",
"## Construct times.\n",
"range_df = chosen_df[chosen_df.system_id == range_system_id]\n",
"times = range_df.timestamp.unique()\n",
"times = chosen_df[chosen_df.system_id == range_system_id].timestamp.unique()\n",
"\n",
"## Construct D.\n",
"D, times = compute_distance_matrix(chosen_df, anchors_df, anchor_names, times, chosen_distance)\n",
Expand All @@ -345,24 +304,28 @@
"outputs": [],
"source": [
"from other_algorithms import pointwise_srls\n",
"from plotting_tools import plot_complexities\n",
"from plotting_backup import plot_complexities_old\n",
"\n",
"list_complexities = [3, 5, 21, 51]\n",
"fig_size = [5, 1.2]\n",
"ylim = [-15, 75]\n",
"\n",
"srls = True\n",
"srls = False\n",
"rls = True\n",
"\n",
"fig, axs = plot_complexities(traj, D, times, anchors, full_df, \n",
" list_complexities, srls=srls)\n",
"anchors = anchors[:2, :]\n",
"fig, axs = plot_complexities_old(traj, D, times, anchors, full_df, \n",
" list_complexities, srls=srls, rls=rls)\n",
"[ax.set_xlim(*xlim) for ax in axs]\n",
"[ax.set_ylim(*ylim) for ax in axs]\n",
"fig.set_size_inches(*fig_size) \n",
"\n",
"if not srls:\n",
" savefig(fig, 'figures/results.pdf')\n",
"if srls:\n",
" savefig(fig, 'figures/results_with_srls.pdf')\n",
"elif rls:\n",
" savefig(fig, 'figures/results_with_rls.pdf')\n",
"else:\n",
" savefig(fig, 'figures/results_with_srls.pdf')"
" savefig(fig, 'figures/results.pdf')"
]
},
{
Expand All @@ -378,7 +341,7 @@
"metadata": {},
"outputs": [],
"source": [
"from plotting_tools import plot_subsample\n",
"from plotting_backup import plot_subsample_old\n",
"\n",
"fig_size = [5, 1.2]\n",
"\n",
Expand All @@ -390,14 +353,24 @@
"#n_measurements_list = [19, 20, 30, 40, 50, 100, 200, 300, 499]\n",
"n_measurements_list = [19, 30, 60, 200][::-1]\n",
"\n",
"fig, axs = plot_subsample(traj, D, times, anchors, full_df, \n",
" n_measurements_list)\n",
"srls = False\n",
"rls = True\n",
"\n",
"fig, axs = plot_subsample_old(traj, D, times, anchors, full_df, \n",
" n_measurements_list, srls=srls, rls=rls)\n",
"[ax.set_xlim(*xlim) for ax in axs]\n",
"[ax.set_ylim(*ylim) for ax in axs]\n",
"fig.set_size_inches(*fig_size)\n",
"\n",
"savefig(fig, 'figures/downsampling.pdf')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
172 changes: 161 additions & 11 deletions IterativeAlgorithms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"import pandas as pd\n",
"import seaborn as sns\n",
"\n",
"from iterative_algorithms import *\n",
"\n",
"\n",
"%matplotlib inline\n",
"#%matplotlib notebook\n",
"%reload_ext autoreload\n",
Expand Down Expand Up @@ -105,7 +108,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Averaging Algorithm\n",
"### 1. Averaging algorithm\n",
"\n",
"Estimate the trajectory recursively over a fixed time window."
]
Expand All @@ -116,7 +119,6 @@
"metadata": {},
"outputs": [],
"source": [
"from iterative_algorithms import averaging_algorithm\n",
"C_list, t_list = averaging_algorithm(D, anchors, F, times, t_window=1.0)\n",
"\n",
"np.testing.assert_allclose(C_list[0], t1.coeffs)\n",
Expand All @@ -127,15 +129,19 @@
"for C, t in zip(C_list, t_list):\n",
" trajk = t1.copy()\n",
" trajk.set_coeffs(coeffs=C)\n",
" trajk.plot(ax=ax, times=t)"
" trajk.plot(ax=ax, times=t)\n",
"fig.set_size_inches(5, 3)\n",
"ax.set_xlabel('x')\n",
"ax.set_ylabel('y')\n",
"plt.tight_layout()\n",
"fig.savefig('results/moving_window.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Build-up Algorithm\n",
"\n",
"### 2. Build-up algorithm\n",
"\n",
"Refine the current trajectory as long as the new measurements \"fit the model\" well enough. \n",
"\n",
Expand All @@ -148,20 +154,164 @@
"metadata": {},
"outputs": [],
"source": [
"from iterative_algorithms import build_up_algorithm\n",
"\n",
"C_list, t_list = build_up_algorithm(D, anchors, F, times, eps=1e-3)\n",
"\n",
"\n",
"np.testing.assert_allclose(C_list[0], t1.coeffs)\n",
"np.testing.assert_allclose(C_list[1], t2.coeffs)\n",
"\n",
"\n",
" \n",
"fig, ax = plt.subplots()\n",
"for C, t in zip(C_list, t_list):\n",
" trajk = t1.copy()\n",
" trajk.set_coeffs(coeffs=C)\n",
" trajk.plot(ax=ax, times=t)"
" trajk.plot(ax=ax, times=t)\n",
"fig.set_size_inches(5, 3)\n",
"ax.set_xlabel('x')\n",
"ax.set_ylabel('y')\n",
"plt.tight_layout()\n",
"fig.savefig('results/iterative.png')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Real example"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from public_data_utils import *\n",
"#filename = 'datasets/uah1.mat' # fingers\n",
"#filename = 'datasets/Plaza1.mat'; # zig zag. \n",
"filename = 'datasets/Plaza2.mat' # triangle\n",
"\n",
"full_df, anchors_df, traj = read_dataset(filename)\n",
"xlim, ylim = get_plotting_params(filename)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from evaluate_dataset import compute_distance_matrix, compute_anchors\n",
"\n",
"chosen_df = full_df\n",
"#chosen_df = filtered_df\n",
"chosen_distance = 'distance'\n",
"#chosen_distance = 'distance_gt'\n",
"anchor_names = None\n",
"\n",
"## Construct anchors. \n",
"anchors = compute_anchors(anchors_df, anchor_names)\n",
"\n",
"## Construct times.\n",
"times = chosen_df[chosen_df.system_id == range_system_id].timestamp.unique()\n",
"\n",
"## Construct D.\n",
"D, times = compute_distance_matrix(chosen_df, anchors_df, anchor_names, times, chosen_distance)\n",
"if np.sum(D > 0) > D.shape[0]:\n",
" print('Warning: multiple measurements for times:{}/{}!'.format(\n",
" np.sum(np.sum(D > 0, axis=1)>1), D.shape[0]))\n",
"\n",
"## Construct ground truth.\n",
"points_gt = get_ground_truth(chosen_df, times)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"period_it = 10\n",
"dataname = filename.split('/')[-1].split('.')[0]\n",
"if dataname == 'uah1':\n",
" # for iterative.\n",
" n_complexity_it = 2\n",
" model_it = 'polynomial'\n",
" t_window_it = 80\n",
" eps = 2.0\n",
"elif dataname == 'Plaza1':\n",
" # for iterative.\n",
" n_complexity_it = 3\n",
" model_it = 'full_bandlimited'\n",
" period_it = 40\n",
" t_window_it = 20\n",
" eps = 0.5\n",
"elif dataname == 'Plaza2':\n",
" # for iterative.\n",
" n_complexity_it = 3\n",
" model_it = 'bandlimited'\n",
" period_it = 40\n",
" t_window_it = 40\n",
" eps = 0.2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"traj_it = traj.copy()\n",
"traj_it.set_n_complexity(n_complexity_it)\n",
"traj_it.model = model_it\n",
"traj_it.period = period_it\n",
"basis = traj_it.get_basis(times=times)\n",
"print('Using trajectory model: \\n model={}, K={}, period={}'.format(traj_it.model, traj_it.n_complexity, traj_it.period))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. Averaging algorithm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print('averaging with time window', t_window_it)\n",
"C_list, t_list = averaging_algorithm(D, anchors[:2, :], basis, times, t_window=t_window_it)\n",
"ax1 = plot_individual(C_list, t_list, traj_it)\n",
"ax1.plot(points_gt.px, points_gt.py, color='black')\n",
"result_df = get_smooth_points(C_list, t_list, traj_it)\n",
"ax2 = plot_smooth(result_df)\n",
"ax2.plot(points_gt.px, points_gt.py, color='black')\n",
"[[ax.set_xlim(*xlim), ax.set_ylim(*ylim)] for ax in [ax1, ax2]]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. Build-up algorithm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"C_list, t_list = build_up_algorithm(D, anchors[:2, :], basis, times, eps=eps, verbose=False)\n",
"ax1 = plot_individual(C_list, t_list, traj_it.copy())\n",
"ax1.plot(points_gt.px, points_gt.py, color='black')\n",
"\n",
"result_df = get_smooth_points(C_list, t_list, traj_it)\n",
"ax2 = plot_smooth(result_df)\n",
"ax2.plot(points_gt.px, points_gt.py, color='black')\n",
"[[ax.set_xlim(*xlim), ax.set_ylim(*ylim)] for ax in [ax1, ax2]]"
]
},
{
Expand Down
Loading

0 comments on commit abf5862

Please sign in to comment.