-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into added_dataset_size
- Loading branch information
Showing
24 changed files
with
1,045 additions
and
1,056 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
|
@@ -38,4 +38,4 @@ | |
"get_normalized_score", | ||
] | ||
|
||
__version__ = "0.4.1" | ||
__version__ = "0.4.2" |
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 |
---|---|---|
@@ -1,29 +1,30 @@ | ||
import h5py | ||
from typing import Dict | ||
|
||
import numpy as np | ||
|
||
|
||
class EpisodeMetadataCallback: | ||
"""Callback to full episode after saving to hdf5 file as a group. | ||
This callback can be overridden to add extra metadata attributes or statistics to | ||
each HDF5 episode group in the Minari dataset. The custom callback can then be | ||
each episode in the Minari dataset. The custom callback can then be | ||
passed to the DataCollectorV0 wrapper to the `episode_metadata_callback` argument. | ||
TODO: add more default statistics to episode datasets | ||
""" | ||
|
||
def __call__(self, eps_group: h5py.Group): | ||
def __call__(self, episode: Dict): | ||
"""Callback method. | ||
Override this method to add custom attribute metadata to the episode group. | ||
Args: | ||
eps_group (h5py.Group): the HDF5 group that contains an episode's datasets | ||
episode (dict): the dict that contains an episode's data | ||
""" | ||
eps_group["rewards"].attrs["sum"] = np.sum(eps_group["rewards"]) | ||
eps_group["rewards"].attrs["mean"] = np.mean(eps_group["rewards"]) | ||
eps_group["rewards"].attrs["std"] = np.std(eps_group["rewards"]) | ||
eps_group["rewards"].attrs["max"] = np.max(eps_group["rewards"]) | ||
eps_group["rewards"].attrs["min"] = np.min(eps_group["rewards"]) | ||
|
||
eps_group.attrs["total_steps"] = eps_group["rewards"].shape[0] | ||
return { | ||
"rewards_sum": np.sum(episode["rewards"]), | ||
"rewards_mean": np.mean(episode["rewards"]), | ||
"rewards_std": np.std(episode["rewards"]), | ||
"rewards_max": np.max(episode["rewards"]), | ||
"rewards_min": np.min(episode["rewards"]), | ||
} |
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
Oops, something went wrong.