common_tools

xuance.common.common_tools.create_directory(path)[source]

Create an empty directory. :param path: the path of the directory

xuance.common.common_tools.discount_cumsum(x, discount=0.99)[source]

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.

Returns:

The discounted cumulative returns for each step.

Examples

>>> 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)[source]

Get arguments from .yaml files :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.

Returns:

the SimpleNamespace variables that contains attributes for DRL implementations.

Return type:

args

xuance.common.common_tools.get_time_string()[source]
xuance.common.common_tools.load_yaml(file_dir) dict[source]

Get dict variable from a YAML file. :param file_dir: the directory of the YAML file.

Returns:

the keys and corresponding values in the YAML file.

Return type:

config_dict

xuance.common.common_tools.recursive_dict_update(basic_dict, target_dict)[source]

Update the dict values.

Parameters:
  • basic_dict – the original dict variable that to be updated.

  • target_dict – the target dict variable with new values.

Returns:

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}