common_tools¶
- xuance.common.common_tools.create_directory(path)[源代码]¶
Create an empty directory. :param path: the path of the directory
- xuance.common.common_tools.discount_cumsum(x, discount=0.99)[源代码]¶
Get a discounted cumulated summation. :param x: The original sequence. In DRL, x can be reward sequence. :param discount: the discount factor (gamma), default is 0.99.
- 返回:
The discounted cumulative returns for each step.
示例
>>> x = [0, 1, 2, 2] >>> y = discount_cumsum(x, discount=0.99) [4.890798, 4.9402, 3.98, 2.0]
- xuance.common.common_tools.get_arguments(algo, env, env_id, config_path=None, parser_args=None)[源代码]¶
Get arguments from
.yamlfiles :param algo: the algorithm name that will be implemented, :param env: The name of the environment, :param env_id: The name of the scenario in the environment. :param config_path: default is None, if None, the default configs (xuance/configs/.../*.yaml) will be loaded. :param parser_args: arguments that specified by parser tools.- 返回:
the SimpleNamespace variables that contains attributes for DRL implementations.
- 返回类型:
args
- xuance.common.common_tools.get_configs(file_dir)[源代码]¶
Get dict variable from a YAML file. :param file_dir: the directory of the YAML file.
- 返回:
the keys and corresponding values in the YAML file.
- 返回类型:
config_dict
- xuance.common.common_tools.recursive_dict_update(basic_dict, target_dict)[源代码]¶
Update the dict values.
- 参数:
basic_dict – the original dict variable that to be updated.
target_dict – the target dict variable with new values.
- 返回:
A dict mapping keys of basic_dict to the values of the same keys in target_dict. For example:
basic_dict = {‘a’: 1, ‘b’: 2} target_dict = {‘a’: 3, ‘c’: 4} out_dict = recursive_dict_update(basic_dict, target_dict)
output_dict = {‘a’: 3, ‘b’: 2, ‘c’: 4}