Skip to content

Commit

Permalink
need to implement new flag for restarting experiments from a particul…
Browse files Browse the repository at this point in the history
…ar online learning cycle
  • Loading branch information
NishanthJKumar committed Jul 18, 2023
1 parent ae552ff commit 86b5787
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 30 deletions.
24 changes: 24 additions & 0 deletions predicators/approaches/active_sampler_learning_approach.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ def _create_explorer(self) -> BaseExplorer:
nsrt_to_explorer_sampler=self._nsrt_to_explorer_sampler)
return explorer

def load(self, online_learning_cycle: Optional[int]) -> None:
super().load(online_learning_cycle)
save_path = utils.get_approach_load_path_str()
with open(f"{save_path}_{online_learning_cycle}.DATA", "rb") as f:
save_dict = pkl.load(f)
self._sampler_data = save_dict["sampler_data"]
self._ground_op_hist = save_dict["ground_op_hist"]
self._last_seen_segment_traj_idx = save_dict[
"last_seen_segment_traj_idx"]
self._nsrt_to_explorer_sampler = save_dict["nsrt_to_explorer_sampler"]
self._online_learning_cycle = CFG.skip_until_cycle + 1

def _learn_nsrts(self, trajectories: List[LowLevelTrajectory],
online_learning_cycle: Optional[int],
annotations: Optional[List[Any]]) -> None:
Expand All @@ -99,6 +111,18 @@ def _learn_nsrts(self, trajectories: List[LowLevelTrajectory],
self._update_sampler_data()
# Re-learn samplers. Updates the NSRTs.
self._learn_wrapped_samplers(online_learning_cycle)
# Save the things we need other than the NSRTs, which were already
# saved in the above call to self._learn_nsrts()
save_path = utils.get_approach_save_path_str()
with open(f"{save_path}_{online_learning_cycle}.DATA", "wb") as f:
pkl.dump(
{
"sampler_data": self._sampler_data,
"ground_op_hist": self._ground_op_hist,
"last_seen_segment_traj_idx":
self._last_seen_segment_traj_idx,
"nsrt_to_explorer_sampler": self._nsrt_to_explorer_sampler,
}, f)

def _update_sampler_data(self) -> None:
start_idx = self._last_seen_segment_traj_idx + 1
Expand Down
64 changes: 34 additions & 30 deletions scripts/plotting/create_active_sampler_learning_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,40 @@
# The keys of the outer dict are plot titles.
# The keys of the inner dict are (legend label, marker, df selector).
PLOT_GROUPS = {
"Bumpy Cover": [
("Approach v0", "black", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "bumpy_cover-random-explore" in v)),
],
"Shifted Bumpy Cover": [
("Myopic Classifier", "green", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "bumpy_cover-myopic_classifier_mlp" in v)),
("Fitted Q", "purple", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "bumpy_cover-fitted_q" in v)),
("Teacher Classifier", "brown", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "bumpy_cover-teacher_classifier" in v)),
],
"Regional Bumpy Cover": [
("Active Explore No Ensemble", "blue", lambda df: df["EXPERIMENT_ID"].
apply(lambda v: "regional_bumpy_cover-main" in v)),
("Active Explore Ensemble", "green", lambda df: df["EXPERIMENT_ID"].
apply(lambda v: "regional_bumpy_cover-ensemble" in v)),
("Random Explore", "red", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "regional_bumpy_cover-random-explore" in v)),
],
"Bumpy Cover Feature Design": [
("All Feats (MLP)", "black", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "bumpy_cover-mlp_all_features" in v)),
("Oracle Feats (MLP)", "green", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "bumpy_cover-mlp_manual_features" in v)),
("All Feats (KNN)", "blue", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "bumpy_cover-knn_all_features" in v)),
("Oracle Feats (KNN)", "red", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "bumpy_cover-knn_manual_features" in v)),
],
# "Bumpy Cover": [
# ("Approach v0", "black", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "bumpy_cover-random-explore" in v)),
# ],
# "Shifted Bumpy Cover": [
# ("Myopic Classifier", "green", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "bumpy_cover-myopic_classifier_mlp" in v)),
# ("Fitted Q", "purple", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "bumpy_cover-fitted_q" in v)),
# ("Teacher Classifier", "brown", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "bumpy_cover-teacher_classifier" in v)),
# ],
# "Regional Bumpy Cover": [
# ("Active Explore No Ensemble", "blue", lambda df: df["EXPERIMENT_ID"].
# apply(lambda v: "regional_bumpy_cover-main" in v)),
# ("Active Explore Ensemble", "green", lambda df: df["EXPERIMENT_ID"].
# apply(lambda v: "regional_bumpy_cover-ensemble" in v)),
# ("Random Explore", "red", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "regional_bumpy_cover-random-explore" in v)),
# ],
# "Bumpy Cover Feature Design": [
# ("All Feats (MLP)", "black", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "bumpy_cover-mlp_all_features" in v)),
# ("Oracle Feats (MLP)", "green", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "bumpy_cover-mlp_manual_features" in v)),
# ("All Feats (KNN)", "blue", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "bumpy_cover-knn_all_features" in v)),
# ("Oracle Feats (KNN)", "red", lambda df: df["EXPERIMENT_ID"].apply(
# lambda v: "bumpy_cover-knn_manual_features" in v)),
# ],
"Spot Two Tables": [
("Random NSRTs", "black", lambda df: df["EXPERIMENT_ID"].apply(
lambda v: "spot_bike_env-two_tables-random_nsrts" in v)),
]
}

# If True, add (0, 0) to every plot.
Expand Down

0 comments on commit 86b5787

Please sign in to comment.