Skip to content

Commit 61602f2

Browse files
committed
Add active data selector
F Unify data selection options
1 parent 28cbacc commit 61602f2

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ registry?=ethzasl/data-driven-dynamics
55
model?=quadrotor_model
66
log?=${root_dir}/resources/${model}.ulg
77
config?=${root_dir}/Tools/parametric_model/configs/${model}.yaml
8-
data_selection?=False
8+
data_selection?=none
99
plot?=True
1010

1111
submodulesupdate:

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ source setup.bash
8484
Generate the parametric model using a log file (ulog or csv):
8585

8686
```
87-
make estimate-model [model=<modeltype>] [config=<config_file_path>] [data_selection=<True/False>] [plot=<True/False>] log=<log_file_path>
87+
make estimate-model [model=<modeltype>] [config=<config_file_path>] [data_selection=<none|interwactive|auto>] [plot=<True/False>] log=<log_file_path>
8888
```
8989

9090
### Pipeline Arguments
@@ -106,7 +106,10 @@ The Log file contains all data needed for the system identification of the speci
106106

107107
#### Data Selection
108108

109-
The data_selection argument is optional (per default False) and can be used to visually select subportions of the data, using the [Visual Dataframe Selector](https://github.com/manumerous/visual_dataframe_selector), before running the model estimation. It is also possible to save the selected subportion of data to a csv file in order to use this exact dataset multiple times.
109+
The data_selection argument is optional (per default none) and can be used to visually select subportions of the data.
110+
- none(default): Data selection is disabled, and the whole section of the log is used
111+
- interactive: Data is selected interactively using the [Visual Dataframe Selector](https://github.com/manumerous/visual_dataframe_selector), before running the model estimation. It is also possible to save the selected subportion of data to a csv file in order to use this exact dataset multiple times.
112+
- auto: Data is selected automatically (Beta)
110113

111114
### Results
112115

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class ActiveDataSelector():
2+
def __init__(self, data_df):
3+
self.data_df = data_df
4+
5+
def select_dataframes(self, ratio = 10):
6+
idx = self.data_df.sort_values(by=["fisher_information_force"]).index[0:self.data_df.shape[0]*10//100]
7+
idx = idx.append(self.data_df.sort_values(by=["fisher_information_rot"]).index[0:self.data_df.shape[0]*10//100])
8+
idx = idx.unique()
9+
idx = idx.sort_values()
10+
self.data_df = self.data_df.loc[idx]
11+
self.data_df.reset_index(drop=True)
12+
return self.data_df

Tools/parametric_model/generate_parametric_model.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ def str2bool(v):
5656
raise argparse.ArgumentTypeError('Boolean value expected.')
5757

5858

59-
def start_model_estimation(config, log_path, data_selection=False, plot=False):
59+
def start_model_estimation(config, log_path, data_selection="none", plot=False):
6060
print("Visual Data selection enabled: ", data_selection)
6161

6262
# Flag for enabling automatic data selection.
63-
# TODO: Unify data selection type with auto and manual
64-
auto_data_selection=False
6563

6664
data_handler = DataHandler(config)
6765
data_handler.loadLogs(log_path)
@@ -97,22 +95,20 @@ def start_model_estimation(config, log_path, data_selection=False, plot=False):
9795
model.compute_fisher_information()
9896

9997
# Interactive data selection
100-
if data_selection:
98+
if data_selection=="interactive":
10199
from visual_dataframe_selector.data_selector import select_visual_data
102100
model.data_df = select_visual_data(model.data_df,visual_dataframe_selector_config_dict)
103101
model.n_samples = model.data_df.shape[0]
104102
# Automatic data selection (WIP)
105-
elif auto_data_selection:
103+
elif data_selection=="auto":
104+
from active_dataframe_selector.data_selector import ActiveDataSelector
106105
# The goal is to identify automatically the most relevant parts of a log.
107106
# Currently the draft is designed to choose the most informative 10% of the logs with regards to
108107
# force and moment parameters. This threshold is currently not validated at all and the percentage
109108
# can vary drastically from log to log.
110-
idx = model.data_df.sort_values(by=["fisher_information_force"]).index[0:model.data_df.shape[0]*10//100]
111-
idx = idx.append(model.data_df.sort_values(by=["fisher_information_rot"]).index[0:model.data_df.shape[0]*10//100])
112-
idx = idx.unique()
113-
idx = idx.sort_values()
114-
model.data_df = model.data_df.loc[idx]
115-
model.data_df.reset_index(drop=True)
109+
110+
data_selector = ActiveDataSelector(model.data_df)
111+
model.data_df = data_selector.select_dataframes(10)
116112
model.n_samples = model.data_df.shape[0]
117113

118114
model.estimate_model()
@@ -129,8 +125,8 @@ def start_model_estimation(config, log_path, data_selection=False, plot=False):
129125
description='Estimate dynamics model from flight log.')
130126
parser.add_argument('log_path', metavar='log_path', type=str,
131127
help='The path of the log to process relative to the project directory.')
132-
parser.add_argument('--data_selection', metavar='data_selection', type=str2bool, default=False,
133-
help='the path of the log to process relative to the project directory.')
128+
parser.add_argument('--data_selection', metavar='data_selection', type=str, default="none",
129+
help='Data selection scheme none | interactive | auto (Beta)')
134130
parser.add_argument('--config', metavar='config', type=str, default='configs/quadrotor_model.yaml',
135131
help='Configuration file path for pipeline configurations')
136132
parser.add_argument('--plot', metavar='plot', type=str2bool, default='True',

0 commit comments

Comments
 (0)