repo
stringclasses
85 values
path
stringlengths
8
121
func_name
stringlengths
1
82
original_string
stringlengths
112
65.5k
language
stringclasses
1 value
code
stringlengths
112
65.5k
code_tokens
listlengths
20
4.09k
docstring
stringlengths
3
46.3k
docstring_tokens
listlengths
1
564
sha
stringclasses
85 values
url
stringlengths
93
218
partition
stringclasses
1 value
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/policy.py
Policy.get_current_step
def get_current_step(self): """ Gets current model step. :return: current model step. """ step = self.sess.run(self.model.global_step) return step
python
def get_current_step(self): """ Gets current model step. :return: current model step. """ step = self.sess.run(self.model.global_step) return step
[ "def", "get_current_step", "(", "self", ")", ":", "step", "=", "self", ".", "sess", ".", "run", "(", "self", ".", "model", ".", "global_step", ")", "return", "step" ]
Gets current model step. :return: current model step.
[ "Gets", "current", "model", "step", ".", ":", "return", ":", "current", "model", "step", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/policy.py#L147-L153
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/policy.py
Policy.save_model
def save_model(self, steps): """ Saves the model :param steps: The number of steps the model was trained for :return: """ with self.graph.as_default(): last_checkpoint = self.model_path + '/model-' + str(steps) + '.cptk' self.saver.save(self.sess, ...
python
def save_model(self, steps): """ Saves the model :param steps: The number of steps the model was trained for :return: """ with self.graph.as_default(): last_checkpoint = self.model_path + '/model-' + str(steps) + '.cptk' self.saver.save(self.sess, ...
[ "def", "save_model", "(", "self", ",", "steps", ")", ":", "with", "self", ".", "graph", ".", "as_default", "(", ")", ":", "last_checkpoint", "=", "self", ".", "model_path", "+", "'/model-'", "+", "str", "(", "steps", ")", "+", "'.cptk'", "self", ".", ...
Saves the model :param steps: The number of steps the model was trained for :return:
[ "Saves", "the", "model", ":", "param", "steps", ":", "The", "number", "of", "steps", "the", "model", "was", "trained", "for", ":", "return", ":" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/policy.py#L173-L183
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/policy.py
Policy.export_model
def export_model(self): """ Exports latest saved model to .nn format for Unity embedding. """ with self.graph.as_default(): target_nodes = ','.join(self._process_graph()) ckpt = tf.train.get_checkpoint_state(self.model_path) freeze_graph.freeze_graph(...
python
def export_model(self): """ Exports latest saved model to .nn format for Unity embedding. """ with self.graph.as_default(): target_nodes = ','.join(self._process_graph()) ckpt = tf.train.get_checkpoint_state(self.model_path) freeze_graph.freeze_graph(...
[ "def", "export_model", "(", "self", ")", ":", "with", "self", ".", "graph", ".", "as_default", "(", ")", ":", "target_nodes", "=", "','", ".", "join", "(", "self", ".", "_process_graph", "(", ")", ")", "ckpt", "=", "tf", ".", "train", ".", "get_check...
Exports latest saved model to .nn format for Unity embedding.
[ "Exports", "latest", "saved", "model", "to", ".", "nn", "format", "for", "Unity", "embedding", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/policy.py#L185-L204
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/policy.py
Policy._process_graph
def _process_graph(self): """ Gets the list of the output nodes present in the graph for inference :return: list of node names """ all_nodes = [x.name for x in self.graph.as_graph_def().node] nodes = [x for x in all_nodes if x in self.possible_output_nodes] logger...
python
def _process_graph(self): """ Gets the list of the output nodes present in the graph for inference :return: list of node names """ all_nodes = [x.name for x in self.graph.as_graph_def().node] nodes = [x for x in all_nodes if x in self.possible_output_nodes] logger...
[ "def", "_process_graph", "(", "self", ")", ":", "all_nodes", "=", "[", "x", ".", "name", "for", "x", "in", "self", ".", "graph", ".", "as_graph_def", "(", ")", ".", "node", "]", "nodes", "=", "[", "x", "for", "x", "in", "all_nodes", "if", "x", "i...
Gets the list of the output nodes present in the graph for inference :return: list of node names
[ "Gets", "the", "list", "of", "the", "output", "nodes", "present", "in", "the", "graph", "for", "inference", ":", "return", ":", "list", "of", "node", "names" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/policy.py#L206-L216
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/buffer.py
Buffer.reset_local_buffers
def reset_local_buffers(self): """ Resets all the local local_buffers """ agent_ids = list(self.keys()) for k in agent_ids: self[k].reset_agent()
python
def reset_local_buffers(self): """ Resets all the local local_buffers """ agent_ids = list(self.keys()) for k in agent_ids: self[k].reset_agent()
[ "def", "reset_local_buffers", "(", "self", ")", ":", "agent_ids", "=", "list", "(", "self", ".", "keys", "(", ")", ")", "for", "k", "in", "agent_ids", ":", "self", "[", "k", "]", ".", "reset_agent", "(", ")" ]
Resets all the local local_buffers
[ "Resets", "all", "the", "local", "local_buffers" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/buffer.py#L221-L227
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/buffer.py
Buffer.append_update_buffer
def append_update_buffer(self, agent_id, key_list=None, batch_size=None, training_length=None): """ Appends the buffer of an agent to the update buffer. :param agent_id: The id of the agent which data will be appended :param key_list: The fields that must be added. If None: all fields wi...
python
def append_update_buffer(self, agent_id, key_list=None, batch_size=None, training_length=None): """ Appends the buffer of an agent to the update buffer. :param agent_id: The id of the agent which data will be appended :param key_list: The fields that must be added. If None: all fields wi...
[ "def", "append_update_buffer", "(", "self", ",", "agent_id", ",", "key_list", "=", "None", ",", "batch_size", "=", "None", ",", "training_length", "=", "None", ")", ":", "if", "key_list", "is", "None", ":", "key_list", "=", "self", "[", "agent_id", "]", ...
Appends the buffer of an agent to the update buffer. :param agent_id: The id of the agent which data will be appended :param key_list: The fields that must be added. If None: all fields will be appended. :param batch_size: The number of elements that must be appended. If None: All of them will b...
[ "Appends", "the", "buffer", "of", "an", "agent", "to", "the", "update", "buffer", ".", ":", "param", "agent_id", ":", "The", "id", "of", "the", "agent", "which", "data", "will", "be", "appended", ":", "param", "key_list", ":", "The", "fields", "that", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/buffer.py#L229-L245
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/buffer.py
Buffer.append_all_agent_batch_to_update_buffer
def append_all_agent_batch_to_update_buffer(self, key_list=None, batch_size=None, training_length=None): """ Appends the buffer of all agents to the update buffer. :param key_list: The fields that must be added. If None: all fields will be appended. :param batch_size: The number of eleme...
python
def append_all_agent_batch_to_update_buffer(self, key_list=None, batch_size=None, training_length=None): """ Appends the buffer of all agents to the update buffer. :param key_list: The fields that must be added. If None: all fields will be appended. :param batch_size: The number of eleme...
[ "def", "append_all_agent_batch_to_update_buffer", "(", "self", ",", "key_list", "=", "None", ",", "batch_size", "=", "None", ",", "training_length", "=", "None", ")", ":", "for", "agent_id", "in", "self", ".", "keys", "(", ")", ":", "self", ".", "append_upda...
Appends the buffer of all agents to the update buffer. :param key_list: The fields that must be added. If None: all fields will be appended. :param batch_size: The number of elements that must be appended. If None: All of them will be. :param training_length: The length of the samples that must ...
[ "Appends", "the", "buffer", "of", "all", "agents", "to", "the", "update", "buffer", ".", ":", "param", "key_list", ":", "The", "fields", "that", "must", "be", "added", ".", "If", "None", ":", "all", "fields", "will", "be", "appended", ".", ":", "param"...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/buffer.py#L247-L255
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/learn.py
run_training
def run_training(sub_id: int, run_seed: int, run_options, process_queue): """ Launches training session. :param process_queue: Queue used to send signal back to main. :param sub_id: Unique id for training session. :param run_seed: Random seed used for training. :param run_options: Command line a...
python
def run_training(sub_id: int, run_seed: int, run_options, process_queue): """ Launches training session. :param process_queue: Queue used to send signal back to main. :param sub_id: Unique id for training session. :param run_seed: Random seed used for training. :param run_options: Command line a...
[ "def", "run_training", "(", "sub_id", ":", "int", ",", "run_seed", ":", "int", ",", "run_options", ",", "process_queue", ")", ":", "# Docker Parameters", "docker_target_name", "=", "(", "run_options", "[", "'--docker-target-name'", "]", "if", "run_options", "[", ...
Launches training session. :param process_queue: Queue used to send signal back to main. :param sub_id: Unique id for training session. :param run_seed: Random seed used for training. :param run_options: Command line arguments for training.
[ "Launches", "training", "session", ".", ":", "param", "process_queue", ":", "Queue", "used", "to", "send", "signal", "back", "to", "main", ".", ":", "param", "sub_id", ":", "Unique", "id", "for", "training", "session", ".", ":", "param", "run_seed", ":", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/learn.py#L24-L95
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer.py
Trainer.get_action
def get_action(self, curr_info: BrainInfo) -> ActionInfo: """ Get an action using this trainer's current policy. :param curr_info: Current BrainInfo. :return: The ActionInfo given by the policy given the BrainInfo. """ self.trainer_metrics.start_experience_collection_time...
python
def get_action(self, curr_info: BrainInfo) -> ActionInfo: """ Get an action using this trainer's current policy. :param curr_info: Current BrainInfo. :return: The ActionInfo given by the policy given the BrainInfo. """ self.trainer_metrics.start_experience_collection_time...
[ "def", "get_action", "(", "self", ",", "curr_info", ":", "BrainInfo", ")", "->", "ActionInfo", ":", "self", ".", "trainer_metrics", ".", "start_experience_collection_timer", "(", ")", "action", "=", "self", ".", "policy", ".", "get_action", "(", "curr_info", "...
Get an action using this trainer's current policy. :param curr_info: Current BrainInfo. :return: The ActionInfo given by the policy given the BrainInfo.
[ "Get", "an", "action", "using", "this", "trainer", "s", "current", "policy", ".", ":", "param", "curr_info", ":", "Current", "BrainInfo", ".", ":", "return", ":", "The", "ActionInfo", "given", "by", "the", "policy", "given", "the", "BrainInfo", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer.py#L106-L115
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer.py
Trainer.write_summary
def write_summary(self, global_step, delta_train_start, lesson_num=0): """ Saves training statistics to Tensorboard. :param delta_train_start: Time elapsed since training started. :param lesson_num: Current lesson number in curriculum. :param global_step: The number of steps the...
python
def write_summary(self, global_step, delta_train_start, lesson_num=0): """ Saves training statistics to Tensorboard. :param delta_train_start: Time elapsed since training started. :param lesson_num: Current lesson number in curriculum. :param global_step: The number of steps the...
[ "def", "write_summary", "(", "self", ",", "global_step", ",", "delta_train_start", ",", "lesson_num", "=", "0", ")", ":", "if", "global_step", "%", "self", ".", "trainer_parameters", "[", "'summary_freq'", "]", "==", "0", "and", "global_step", "!=", "0", ":"...
Saves training statistics to Tensorboard. :param delta_train_start: Time elapsed since training started. :param lesson_num: Current lesson number in curriculum. :param global_step: The number of steps the simulation has been going for
[ "Saves", "training", "statistics", "to", "Tensorboard", ".", ":", "param", "delta_train_start", ":", "Time", "elapsed", "since", "training", "started", ".", ":", "param", "lesson_num", ":", "Current", "lesson", "number", "in", "curriculum", ".", ":", "param", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer.py#L180-L215
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer.py
Trainer.write_tensorboard_text
def write_tensorboard_text(self, key, input_dict): """ Saves text to Tensorboard. Note: Only works on tensorflow r1.2 or above. :param key: The name of the text. :param input_dict: A dictionary that will be displayed in a table on Tensorboard. """ try: ...
python
def write_tensorboard_text(self, key, input_dict): """ Saves text to Tensorboard. Note: Only works on tensorflow r1.2 or above. :param key: The name of the text. :param input_dict: A dictionary that will be displayed in a table on Tensorboard. """ try: ...
[ "def", "write_tensorboard_text", "(", "self", ",", "key", ",", "input_dict", ")", ":", "try", ":", "with", "tf", ".", "Session", "(", ")", "as", "sess", ":", "s_op", "=", "tf", ".", "summary", ".", "text", "(", "key", ",", "tf", ".", "convert_to_tens...
Saves text to Tensorboard. Note: Only works on tensorflow r1.2 or above. :param key: The name of the text. :param input_dict: A dictionary that will be displayed in a table on Tensorboard.
[ "Saves", "text", "to", "Tensorboard", ".", "Note", ":", "Only", "works", "on", "tensorflow", "r1", ".", "2", "or", "above", ".", ":", "param", "key", ":", "The", "name", "of", "the", "text", ".", ":", "param", "input_dict", ":", "A", "dictionary", "t...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer.py#L217-L233
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/meta_curriculum.py
MetaCurriculum.lesson_nums
def lesson_nums(self): """A dict from brain name to the brain's curriculum's lesson number.""" lesson_nums = {} for brain_name, curriculum in self.brains_to_curriculums.items(): lesson_nums[brain_name] = curriculum.lesson_num return lesson_nums
python
def lesson_nums(self): """A dict from brain name to the brain's curriculum's lesson number.""" lesson_nums = {} for brain_name, curriculum in self.brains_to_curriculums.items(): lesson_nums[brain_name] = curriculum.lesson_num return lesson_nums
[ "def", "lesson_nums", "(", "self", ")", ":", "lesson_nums", "=", "{", "}", "for", "brain_name", ",", "curriculum", "in", "self", ".", "brains_to_curriculums", ".", "items", "(", ")", ":", "lesson_nums", "[", "brain_name", "]", "=", "curriculum", ".", "less...
A dict from brain name to the brain's curriculum's lesson number.
[ "A", "dict", "from", "brain", "name", "to", "the", "brain", "s", "curriculum", "s", "lesson", "number", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/meta_curriculum.py#L61-L67
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/meta_curriculum.py
MetaCurriculum.increment_lessons
def increment_lessons(self, measure_vals, reward_buff_sizes=None): """Attempts to increments all the lessons of all the curriculums in this MetaCurriculum. Note that calling this method does not guarantee the lesson of a curriculum will increment. The lesson of a curriculum will only inc...
python
def increment_lessons(self, measure_vals, reward_buff_sizes=None): """Attempts to increments all the lessons of all the curriculums in this MetaCurriculum. Note that calling this method does not guarantee the lesson of a curriculum will increment. The lesson of a curriculum will only inc...
[ "def", "increment_lessons", "(", "self", ",", "measure_vals", ",", "reward_buff_sizes", "=", "None", ")", ":", "ret", "=", "{", "}", "if", "reward_buff_sizes", ":", "for", "brain_name", ",", "buff_size", "in", "reward_buff_sizes", ".", "items", "(", ")", ":"...
Attempts to increments all the lessons of all the curriculums in this MetaCurriculum. Note that calling this method does not guarantee the lesson of a curriculum will increment. The lesson of a curriculum will only increment if the specified measure threshold defined in the curriculum ha...
[ "Attempts", "to", "increments", "all", "the", "lessons", "of", "all", "the", "curriculums", "in", "this", "MetaCurriculum", ".", "Note", "that", "calling", "this", "method", "does", "not", "guarantee", "the", "lesson", "of", "a", "curriculum", "will", "increme...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/meta_curriculum.py#L91-L119
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/meta_curriculum.py
MetaCurriculum.set_all_curriculums_to_lesson_num
def set_all_curriculums_to_lesson_num(self, lesson_num): """Sets all the curriculums in this meta curriculum to a specified lesson number. Args: lesson_num (int): The lesson number which all the curriculums will be set to. """ for _, curriculum in sel...
python
def set_all_curriculums_to_lesson_num(self, lesson_num): """Sets all the curriculums in this meta curriculum to a specified lesson number. Args: lesson_num (int): The lesson number which all the curriculums will be set to. """ for _, curriculum in sel...
[ "def", "set_all_curriculums_to_lesson_num", "(", "self", ",", "lesson_num", ")", ":", "for", "_", ",", "curriculum", "in", "self", ".", "brains_to_curriculums", ".", "items", "(", ")", ":", "curriculum", ".", "lesson_num", "=", "lesson_num" ]
Sets all the curriculums in this meta curriculum to a specified lesson number. Args: lesson_num (int): The lesson number which all the curriculums will be set to.
[ "Sets", "all", "the", "curriculums", "in", "this", "meta", "curriculum", "to", "a", "specified", "lesson", "number", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/meta_curriculum.py#L122-L131
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/meta_curriculum.py
MetaCurriculum.get_config
def get_config(self): """Get the combined configuration of all curriculums in this MetaCurriculum. Returns: A dict from parameter to value. """ config = {} for _, curriculum in self.brains_to_curriculums.items(): curr_config = curriculum.get_conf...
python
def get_config(self): """Get the combined configuration of all curriculums in this MetaCurriculum. Returns: A dict from parameter to value. """ config = {} for _, curriculum in self.brains_to_curriculums.items(): curr_config = curriculum.get_conf...
[ "def", "get_config", "(", "self", ")", ":", "config", "=", "{", "}", "for", "_", ",", "curriculum", "in", "self", ".", "brains_to_curriculums", ".", "items", "(", ")", ":", "curr_config", "=", "curriculum", ".", "get_config", "(", ")", "config", ".", "...
Get the combined configuration of all curriculums in this MetaCurriculum. Returns: A dict from parameter to value.
[ "Get", "the", "combined", "configuration", "of", "all", "curriculums", "in", "this", "MetaCurriculum", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/meta_curriculum.py#L134-L147
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/environment.py
UnityEnvironment.reset
def reset(self, config=None, train_mode=True, custom_reset_parameters=None) -> AllBrainInfo: """ Sends a signal to reset the unity environment. :return: AllBrainInfo : A data structure corresponding to the initial reset state of the environment. """ if config is None: ...
python
def reset(self, config=None, train_mode=True, custom_reset_parameters=None) -> AllBrainInfo: """ Sends a signal to reset the unity environment. :return: AllBrainInfo : A data structure corresponding to the initial reset state of the environment. """ if config is None: ...
[ "def", "reset", "(", "self", ",", "config", "=", "None", ",", "train_mode", "=", "True", ",", "custom_reset_parameters", "=", "None", ")", "->", "AllBrainInfo", ":", "if", "config", "is", "None", ":", "config", "=", "self", ".", "_resetParameters", "elif",...
Sends a signal to reset the unity environment. :return: AllBrainInfo : A data structure corresponding to the initial reset state of the environment.
[ "Sends", "a", "signal", "to", "reset", "the", "unity", "environment", ".", ":", "return", ":", "AllBrainInfo", ":", "A", "data", "structure", "corresponding", "to", "the", "initial", "reset", "state", "of", "the", "environment", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/environment.py#L246-L279
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/environment.py
UnityEnvironment.step
def step(self, vector_action=None, memory=None, text_action=None, value=None, custom_action=None) -> AllBrainInfo: """ Provides the environment with an action, moves the environment dynamics forward accordingly, and returns observation, state, and reward information to the agent. :param ...
python
def step(self, vector_action=None, memory=None, text_action=None, value=None, custom_action=None) -> AllBrainInfo: """ Provides the environment with an action, moves the environment dynamics forward accordingly, and returns observation, state, and reward information to the agent. :param ...
[ "def", "step", "(", "self", ",", "vector_action", "=", "None", ",", "memory", "=", "None", ",", "text_action", "=", "None", ",", "value", "=", "None", ",", "custom_action", "=", "None", ")", "->", "AllBrainInfo", ":", "vector_action", "=", "{", "}", "i...
Provides the environment with an action, moves the environment dynamics forward accordingly, and returns observation, state, and reward information to the agent. :param value: Value estimates provided by agents. :param vector_action: Agent's vector action. Can be a scalar or vector of int/floats...
[ "Provides", "the", "environment", "with", "an", "action", "moves", "the", "environment", "dynamics", "forward", "accordingly", "and", "returns", "observation", "state", "and", "reward", "information", "to", "the", "agent", ".", ":", "param", "value", ":", "Value...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/environment.py#L281-L451
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/environment.py
UnityEnvironment._flatten
def _flatten(cls, arr) -> List[float]: """ Converts arrays to list. :param arr: numpy vector. :return: flattened list. """ if isinstance(arr, cls.SCALAR_ACTION_TYPES): arr = [float(arr)] if isinstance(arr, np.ndarray): arr = arr.tolist() ...
python
def _flatten(cls, arr) -> List[float]: """ Converts arrays to list. :param arr: numpy vector. :return: flattened list. """ if isinstance(arr, cls.SCALAR_ACTION_TYPES): arr = [float(arr)] if isinstance(arr, np.ndarray): arr = arr.tolist() ...
[ "def", "_flatten", "(", "cls", ",", "arr", ")", "->", "List", "[", "float", "]", ":", "if", "isinstance", "(", "arr", ",", "cls", ".", "SCALAR_ACTION_TYPES", ")", ":", "arr", "=", "[", "float", "(", "arr", ")", "]", "if", "isinstance", "(", "arr", ...
Converts arrays to list. :param arr: numpy vector. :return: flattened list.
[ "Converts", "arrays", "to", "list", ".", ":", "param", "arr", ":", "numpy", "vector", ".", ":", "return", ":", "flattened", "list", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/environment.py#L469-L486
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/environment.py
UnityEnvironment._get_state
def _get_state(self, output: UnityRLOutput) -> (AllBrainInfo, bool): """ Collects experience information from all external brains in environment at current step. :return: a dictionary of BrainInfo objects. """ _data = {} global_done = output.global_done for brain_...
python
def _get_state(self, output: UnityRLOutput) -> (AllBrainInfo, bool): """ Collects experience information from all external brains in environment at current step. :return: a dictionary of BrainInfo objects. """ _data = {} global_done = output.global_done for brain_...
[ "def", "_get_state", "(", "self", ",", "output", ":", "UnityRLOutput", ")", "->", "(", "AllBrainInfo", ",", "bool", ")", ":", "_data", "=", "{", "}", "global_done", "=", "output", ".", "global_done", "for", "brain_name", "in", "output", ".", "agentInfos", ...
Collects experience information from all external brains in environment at current step. :return: a dictionary of BrainInfo objects.
[ "Collects", "experience", "information", "from", "all", "external", "brains", "in", "environment", "at", "current", "step", ".", ":", "return", ":", "a", "dictionary", "of", "BrainInfo", "objects", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/environment.py#L488-L499
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_metrics.py
TrainerMetrics.end_experience_collection_timer
def end_experience_collection_timer(self): """ Inform Metrics class that experience collection is done. """ if self.time_start_experience_collection: curr_delta = time() - self.time_start_experience_collection if self.delta_last_experience_collection is None: ...
python
def end_experience_collection_timer(self): """ Inform Metrics class that experience collection is done. """ if self.time_start_experience_collection: curr_delta = time() - self.time_start_experience_collection if self.delta_last_experience_collection is None: ...
[ "def", "end_experience_collection_timer", "(", "self", ")", ":", "if", "self", ".", "time_start_experience_collection", ":", "curr_delta", "=", "time", "(", ")", "-", "self", ".", "time_start_experience_collection", "if", "self", ".", "delta_last_experience_collection",...
Inform Metrics class that experience collection is done.
[ "Inform", "Metrics", "class", "that", "experience", "collection", "is", "done", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_metrics.py#L39-L49
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_metrics.py
TrainerMetrics.add_delta_step
def add_delta_step(self, delta: float): """ Inform Metrics class about time to step in environment. """ if self.delta_last_experience_collection: self.delta_last_experience_collection += delta else: self.delta_last_experience_collection = delta
python
def add_delta_step(self, delta: float): """ Inform Metrics class about time to step in environment. """ if self.delta_last_experience_collection: self.delta_last_experience_collection += delta else: self.delta_last_experience_collection = delta
[ "def", "add_delta_step", "(", "self", ",", "delta", ":", "float", ")", ":", "if", "self", ".", "delta_last_experience_collection", ":", "self", ".", "delta_last_experience_collection", "+=", "delta", "else", ":", "self", ".", "delta_last_experience_collection", "=",...
Inform Metrics class about time to step in environment.
[ "Inform", "Metrics", "class", "about", "time", "to", "step", "in", "environment", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_metrics.py#L51-L58
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_metrics.py
TrainerMetrics.start_policy_update_timer
def start_policy_update_timer(self, number_experiences: int, mean_return: float): """ Inform Metrics class that policy update has started. :int number_experiences: Number of experiences in Buffer at this point. :float mean_return: Return averaged across all cumulative returns since last ...
python
def start_policy_update_timer(self, number_experiences: int, mean_return: float): """ Inform Metrics class that policy update has started. :int number_experiences: Number of experiences in Buffer at this point. :float mean_return: Return averaged across all cumulative returns since last ...
[ "def", "start_policy_update_timer", "(", "self", ",", "number_experiences", ":", "int", ",", "mean_return", ":", "float", ")", ":", "self", ".", "last_buffer_length", "=", "number_experiences", "self", ".", "last_mean_return", "=", "mean_return", "self", ".", "tim...
Inform Metrics class that policy update has started. :int number_experiences: Number of experiences in Buffer at this point. :float mean_return: Return averaged across all cumulative returns since last policy update
[ "Inform", "Metrics", "class", "that", "policy", "update", "has", "started", ".", ":", "int", "number_experiences", ":", "Number", "of", "experiences", "in", "Buffer", "at", "this", "point", ".", ":", "float", "mean_return", ":", "Return", "averaged", "across",...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_metrics.py#L60-L68
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_metrics.py
TrainerMetrics.end_policy_update
def end_policy_update(self): """ Inform Metrics class that policy update has started. """ if self.time_policy_update_start: self.delta_policy_update = time() - self.time_policy_update_start else: self.delta_policy_update = 0 delta_train_start = tim...
python
def end_policy_update(self): """ Inform Metrics class that policy update has started. """ if self.time_policy_update_start: self.delta_policy_update = time() - self.time_policy_update_start else: self.delta_policy_update = 0 delta_train_start = tim...
[ "def", "end_policy_update", "(", "self", ")", ":", "if", "self", ".", "time_policy_update_start", ":", "self", ".", "delta_policy_update", "=", "time", "(", ")", "-", "self", ".", "time_policy_update_start", "else", ":", "self", ".", "delta_policy_update", "=", ...
Inform Metrics class that policy update has started.
[ "Inform", "Metrics", "class", "that", "policy", "update", "has", "started", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_metrics.py#L79-L97
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_metrics.py
TrainerMetrics.write_training_metrics
def write_training_metrics(self): """ Write Training Metrics to CSV """ with open(self.path, 'w') as file: writer = csv.writer(file) writer.writerow(FIELD_NAMES) for row in self.rows: writer.writerow(row)
python
def write_training_metrics(self): """ Write Training Metrics to CSV """ with open(self.path, 'w') as file: writer = csv.writer(file) writer.writerow(FIELD_NAMES) for row in self.rows: writer.writerow(row)
[ "def", "write_training_metrics", "(", "self", ")", ":", "with", "open", "(", "self", ".", "path", ",", "'w'", ")", "as", "file", ":", "writer", "=", "csv", ".", "writer", "(", "file", ")", "writer", ".", "writerow", "(", "FIELD_NAMES", ")", "for", "r...
Write Training Metrics to CSV
[ "Write", "Training", "Metrics", "to", "CSV" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_metrics.py#L99-L107
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/models.py
PPOModel.create_reward_encoder
def create_reward_encoder(): """Creates TF ops to track and increment recent average cumulative reward.""" last_reward = tf.Variable(0, name="last_reward", trainable=False, dtype=tf.float32) new_reward = tf.placeholder(shape=[], dtype=tf.float32, name='new_reward') update_reward = tf.ass...
python
def create_reward_encoder(): """Creates TF ops to track and increment recent average cumulative reward.""" last_reward = tf.Variable(0, name="last_reward", trainable=False, dtype=tf.float32) new_reward = tf.placeholder(shape=[], dtype=tf.float32, name='new_reward') update_reward = tf.ass...
[ "def", "create_reward_encoder", "(", ")", ":", "last_reward", "=", "tf", ".", "Variable", "(", "0", ",", "name", "=", "\"last_reward\"", ",", "trainable", "=", "False", ",", "dtype", "=", "tf", ".", "float32", ")", "new_reward", "=", "tf", ".", "placehol...
Creates TF ops to track and increment recent average cumulative reward.
[ "Creates", "TF", "ops", "to", "track", "and", "increment", "recent", "average", "cumulative", "reward", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/models.py#L49-L54
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/models.py
PPOModel.create_curiosity_encoders
def create_curiosity_encoders(self): """ Creates state encoders for current and future observations. Used for implementation of Curiosity-driven Exploration by Self-supervised Prediction See https://arxiv.org/abs/1705.05363 for more details. :return: current and future state enc...
python
def create_curiosity_encoders(self): """ Creates state encoders for current and future observations. Used for implementation of Curiosity-driven Exploration by Self-supervised Prediction See https://arxiv.org/abs/1705.05363 for more details. :return: current and future state enc...
[ "def", "create_curiosity_encoders", "(", "self", ")", ":", "encoded_state_list", "=", "[", "]", "encoded_next_state_list", "=", "[", "]", "if", "self", ".", "vis_obs_size", ">", "0", ":", "self", ".", "next_visual_in", "=", "[", "]", "visual_encoders", "=", ...
Creates state encoders for current and future observations. Used for implementation of Curiosity-driven Exploration by Self-supervised Prediction See https://arxiv.org/abs/1705.05363 for more details. :return: current and future state encoder tensors.
[ "Creates", "state", "encoders", "for", "current", "and", "future", "observations", ".", "Used", "for", "implementation", "of", "Curiosity", "-", "driven", "Exploration", "by", "Self", "-", "supervised", "Prediction", "See", "https", ":", "//", "arxiv", ".", "...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/models.py#L56-L114
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/models.py
PPOModel.create_inverse_model
def create_inverse_model(self, encoded_state, encoded_next_state): """ Creates inverse model TensorFlow ops for Curiosity module. Predicts action taken given current and future encoded states. :param encoded_state: Tensor corresponding to encoded current state. :param encoded_nex...
python
def create_inverse_model(self, encoded_state, encoded_next_state): """ Creates inverse model TensorFlow ops for Curiosity module. Predicts action taken given current and future encoded states. :param encoded_state: Tensor corresponding to encoded current state. :param encoded_nex...
[ "def", "create_inverse_model", "(", "self", ",", "encoded_state", ",", "encoded_next_state", ")", ":", "combined_input", "=", "tf", ".", "concat", "(", "[", "encoded_state", ",", "encoded_next_state", "]", ",", "axis", "=", "1", ")", "hidden", "=", "tf", "."...
Creates inverse model TensorFlow ops for Curiosity module. Predicts action taken given current and future encoded states. :param encoded_state: Tensor corresponding to encoded current state. :param encoded_next_state: Tensor corresponding to encoded next state.
[ "Creates", "inverse", "model", "TensorFlow", "ops", "for", "Curiosity", "module", ".", "Predicts", "action", "taken", "given", "current", "and", "future", "encoded", "states", ".", ":", "param", "encoded_state", ":", "Tensor", "corresponding", "to", "encoded", "...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/models.py#L116-L134
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/models.py
PPOModel.create_forward_model
def create_forward_model(self, encoded_state, encoded_next_state): """ Creates forward model TensorFlow ops for Curiosity module. Predicts encoded future state based on encoded current state and given action. :param encoded_state: Tensor corresponding to encoded current state. :p...
python
def create_forward_model(self, encoded_state, encoded_next_state): """ Creates forward model TensorFlow ops for Curiosity module. Predicts encoded future state based on encoded current state and given action. :param encoded_state: Tensor corresponding to encoded current state. :p...
[ "def", "create_forward_model", "(", "self", ",", "encoded_state", ",", "encoded_next_state", ")", ":", "combined_input", "=", "tf", ".", "concat", "(", "[", "encoded_state", ",", "self", ".", "selected_actions", "]", ",", "axis", "=", "1", ")", "hidden", "="...
Creates forward model TensorFlow ops for Curiosity module. Predicts encoded future state based on encoded current state and given action. :param encoded_state: Tensor corresponding to encoded current state. :param encoded_next_state: Tensor corresponding to encoded next state.
[ "Creates", "forward", "model", "TensorFlow", "ops", "for", "Curiosity", "module", ".", "Predicts", "encoded", "future", "state", "based", "on", "encoded", "current", "state", "and", "given", "action", ".", ":", "param", "encoded_state", ":", "Tensor", "correspon...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/models.py#L136-L151
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/models.py
PPOModel.create_ppo_optimizer
def create_ppo_optimizer(self, probs, old_probs, value, entropy, beta, epsilon, lr, max_step): """ Creates training-specific Tensorflow ops for PPO models. :param probs: Current policy probabilities :param old_probs: Past policy probabilities :param value: Current value estimate ...
python
def create_ppo_optimizer(self, probs, old_probs, value, entropy, beta, epsilon, lr, max_step): """ Creates training-specific Tensorflow ops for PPO models. :param probs: Current policy probabilities :param old_probs: Past policy probabilities :param value: Current value estimate ...
[ "def", "create_ppo_optimizer", "(", "self", ",", "probs", ",", "old_probs", ",", "value", ",", "entropy", ",", "beta", ",", "epsilon", ",", "lr", ",", "max_step", ")", ":", "self", ".", "returns_holder", "=", "tf", ".", "placeholder", "(", "shape", "=", ...
Creates training-specific Tensorflow ops for PPO models. :param probs: Current policy probabilities :param old_probs: Past policy probabilities :param value: Current value estimate :param beta: Entropy regularization strength :param entropy: Current policy entropy :param ...
[ "Creates", "training", "-", "specific", "Tensorflow", "ops", "for", "PPO", "models", ".", ":", "param", "probs", ":", "Current", "policy", "probabilities", ":", "param", "old_probs", ":", "Past", "policy", "probabilities", ":", "param", "value", ":", "Current"...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/models.py#L153-L195
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/policy.py
PPOPolicy.evaluate
def evaluate(self, brain_info): """ Evaluates policy for the agent experiences provided. :param brain_info: BrainInfo object containing inputs. :return: Outputs from network as defined by self.inference_dict. """ feed_dict = {self.model.batch_size: len(brain_info.vector_o...
python
def evaluate(self, brain_info): """ Evaluates policy for the agent experiences provided. :param brain_info: BrainInfo object containing inputs. :return: Outputs from network as defined by self.inference_dict. """ feed_dict = {self.model.batch_size: len(brain_info.vector_o...
[ "def", "evaluate", "(", "self", ",", "brain_info", ")", ":", "feed_dict", "=", "{", "self", ".", "model", ".", "batch_size", ":", "len", "(", "brain_info", ".", "vector_observations", ")", ",", "self", ".", "model", ".", "sequence_length", ":", "1", "}",...
Evaluates policy for the agent experiences provided. :param brain_info: BrainInfo object containing inputs. :return: Outputs from network as defined by self.inference_dict.
[ "Evaluates", "policy", "for", "the", "agent", "experiences", "provided", ".", ":", "param", "brain_info", ":", "BrainInfo", "object", "containing", "inputs", ".", ":", "return", ":", "Outputs", "from", "network", "as", "defined", "by", "self", ".", "inference_...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/policy.py#L63-L87
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/policy.py
PPOPolicy.update
def update(self, mini_batch, num_sequences): """ Updates model using buffer. :param num_sequences: Number of trajectories in batch. :param mini_batch: Experience batch. :return: Output from update process. """ feed_dict = {self.model.batch_size: num_sequences, ...
python
def update(self, mini_batch, num_sequences): """ Updates model using buffer. :param num_sequences: Number of trajectories in batch. :param mini_batch: Experience batch. :return: Output from update process. """ feed_dict = {self.model.batch_size: num_sequences, ...
[ "def", "update", "(", "self", ",", "mini_batch", ",", "num_sequences", ")", ":", "feed_dict", "=", "{", "self", ".", "model", ".", "batch_size", ":", "num_sequences", ",", "self", ".", "model", ".", "sequence_length", ":", "self", ".", "sequence_length", "...
Updates model using buffer. :param num_sequences: Number of trajectories in batch. :param mini_batch: Experience batch. :return: Output from update process.
[ "Updates", "model", "using", "buffer", ".", ":", "param", "num_sequences", ":", "Number", "of", "trajectories", "in", "batch", ".", ":", "param", "mini_batch", ":", "Experience", "batch", ".", ":", "return", ":", "Output", "from", "update", "process", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/policy.py#L89-L144
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/policy.py
PPOPolicy.get_intrinsic_rewards
def get_intrinsic_rewards(self, curr_info, next_info): """ Generates intrinsic reward used for Curiosity-based training. :BrainInfo curr_info: Current BrainInfo. :BrainInfo next_info: Next BrainInfo. :return: Intrinsic rewards for all agents. """ if self.use_curio...
python
def get_intrinsic_rewards(self, curr_info, next_info): """ Generates intrinsic reward used for Curiosity-based training. :BrainInfo curr_info: Current BrainInfo. :BrainInfo next_info: Next BrainInfo. :return: Intrinsic rewards for all agents. """ if self.use_curio...
[ "def", "get_intrinsic_rewards", "(", "self", ",", "curr_info", ",", "next_info", ")", ":", "if", "self", ".", "use_curiosity", ":", "if", "len", "(", "curr_info", ".", "agents", ")", "==", "0", ":", "return", "[", "]", "feed_dict", "=", "{", "self", "....
Generates intrinsic reward used for Curiosity-based training. :BrainInfo curr_info: Current BrainInfo. :BrainInfo next_info: Next BrainInfo. :return: Intrinsic rewards for all agents.
[ "Generates", "intrinsic", "reward", "used", "for", "Curiosity", "-", "based", "training", ".", ":", "BrainInfo", "curr_info", ":", "Current", "BrainInfo", ".", ":", "BrainInfo", "next_info", ":", "Next", "BrainInfo", ".", ":", "return", ":", "Intrinsic", "rewa...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/policy.py#L146-L177
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/policy.py
PPOPolicy.get_value_estimate
def get_value_estimate(self, brain_info, idx): """ Generates value estimates for bootstrapping. :param brain_info: BrainInfo to be used for bootstrapping. :param idx: Index in BrainInfo of agent. :return: Value estimate. """ feed_dict = {self.model.batch_size: 1, ...
python
def get_value_estimate(self, brain_info, idx): """ Generates value estimates for bootstrapping. :param brain_info: BrainInfo to be used for bootstrapping. :param idx: Index in BrainInfo of agent. :return: Value estimate. """ feed_dict = {self.model.batch_size: 1, ...
[ "def", "get_value_estimate", "(", "self", ",", "brain_info", ",", "idx", ")", ":", "feed_dict", "=", "{", "self", ".", "model", ".", "batch_size", ":", "1", ",", "self", ".", "model", ".", "sequence_length", ":", "1", "}", "for", "i", "in", "range", ...
Generates value estimates for bootstrapping. :param brain_info: BrainInfo to be used for bootstrapping. :param idx: Index in BrainInfo of agent. :return: Value estimate.
[ "Generates", "value", "estimates", "for", "bootstrapping", ".", ":", "param", "brain_info", ":", "BrainInfo", "to", "be", "used", "for", "bootstrapping", ".", ":", "param", "idx", ":", "Index", "in", "BrainInfo", "of", "agent", ".", ":", "return", ":", "Va...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/policy.py#L179-L199
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/policy.py
PPOPolicy.update_reward
def update_reward(self, new_reward): """ Updates reward value for policy. :param new_reward: New reward to save. """ self.sess.run(self.model.update_reward, feed_dict={self.model.new_reward: new_reward})
python
def update_reward(self, new_reward): """ Updates reward value for policy. :param new_reward: New reward to save. """ self.sess.run(self.model.update_reward, feed_dict={self.model.new_reward: new_reward})
[ "def", "update_reward", "(", "self", ",", "new_reward", ")", ":", "self", ".", "sess", ".", "run", "(", "self", ".", "model", ".", "update_reward", ",", "feed_dict", "=", "{", "self", ".", "model", ".", "new_reward", ":", "new_reward", "}", ")" ]
Updates reward value for policy. :param new_reward: New reward to save.
[ "Updates", "reward", "value", "for", "policy", ".", ":", "param", "new_reward", ":", "New", "reward", "to", "save", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/policy.py#L208-L214
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/bc/trainer.py
BCTrainer.add_experiences
def add_experiences(self, curr_info: AllBrainInfo, next_info: AllBrainInfo, take_action_outputs): """ Adds experiences to each agent's experience history. :param curr_info: Current AllBrainInfo (Dictionary of all current brains and corresponding BrainInfo). :param...
python
def add_experiences(self, curr_info: AllBrainInfo, next_info: AllBrainInfo, take_action_outputs): """ Adds experiences to each agent's experience history. :param curr_info: Current AllBrainInfo (Dictionary of all current brains and corresponding BrainInfo). :param...
[ "def", "add_experiences", "(", "self", ",", "curr_info", ":", "AllBrainInfo", ",", "next_info", ":", "AllBrainInfo", ",", "take_action_outputs", ")", ":", "# Used to collect information about student performance.", "info_student", "=", "curr_info", "[", "self", ".", "br...
Adds experiences to each agent's experience history. :param curr_info: Current AllBrainInfo (Dictionary of all current brains and corresponding BrainInfo). :param next_info: Next AllBrainInfo (Dictionary of all current brains and corresponding BrainInfo). :param take_action_outputs: The outputs ...
[ "Adds", "experiences", "to", "each", "agent", "s", "experience", "history", ".", ":", "param", "curr_info", ":", "Current", "AllBrainInfo", "(", "Dictionary", "of", "all", "current", "brains", "and", "corresponding", "BrainInfo", ")", ".", ":", "param", "next_...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/bc/trainer.py#L87-L114
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/bc/trainer.py
BCTrainer.process_experiences
def process_experiences(self, current_info: AllBrainInfo, next_info: AllBrainInfo): """ Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Current AllB...
python
def process_experiences(self, current_info: AllBrainInfo, next_info: AllBrainInfo): """ Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Current AllB...
[ "def", "process_experiences", "(", "self", ",", "current_info", ":", "AllBrainInfo", ",", "next_info", ":", "AllBrainInfo", ")", ":", "info_student", "=", "next_info", "[", "self", ".", "brain_name", "]", "for", "l", "in", "range", "(", "len", "(", "info_stu...
Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Current AllBrainInfo :param next_info: Next AllBrainInfo
[ "Checks", "agent", "histories", "for", "processing", "condition", "and", "processes", "them", "as", "necessary", ".", "Processing", "involves", "calculating", "value", "and", "advantage", "targets", "for", "model", "updating", "step", ".", ":", "param", "current_i...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/bc/trainer.py#L116-L132
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/bc/trainer.py
BCTrainer.end_episode
def end_episode(self): """ A signal that the Episode has ended. The buffer must be reset. Get only called when the academy resets. """ self.evaluation_buffer.reset_local_buffers() for agent_id in self.cumulative_rewards: self.cumulative_rewards[agent_id] = 0 ...
python
def end_episode(self): """ A signal that the Episode has ended. The buffer must be reset. Get only called when the academy resets. """ self.evaluation_buffer.reset_local_buffers() for agent_id in self.cumulative_rewards: self.cumulative_rewards[agent_id] = 0 ...
[ "def", "end_episode", "(", "self", ")", ":", "self", ".", "evaluation_buffer", ".", "reset_local_buffers", "(", ")", "for", "agent_id", "in", "self", ".", "cumulative_rewards", ":", "self", ".", "cumulative_rewards", "[", "agent_id", "]", "=", "0", "for", "a...
A signal that the Episode has ended. The buffer must be reset. Get only called when the academy resets.
[ "A", "signal", "that", "the", "Episode", "has", "ended", ".", "The", "buffer", "must", "be", "reset", ".", "Get", "only", "called", "when", "the", "academy", "resets", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/bc/trainer.py#L134-L143
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/bc/trainer.py
BCTrainer.update_policy
def update_policy(self): """ Updates the policy. """ self.demonstration_buffer.update_buffer.shuffle() batch_losses = [] num_batches = min(len(self.demonstration_buffer.update_buffer['actions']) // self.n_sequences, self.batches_per_epoch) ...
python
def update_policy(self): """ Updates the policy. """ self.demonstration_buffer.update_buffer.shuffle() batch_losses = [] num_batches = min(len(self.demonstration_buffer.update_buffer['actions']) // self.n_sequences, self.batches_per_epoch) ...
[ "def", "update_policy", "(", "self", ")", ":", "self", ".", "demonstration_buffer", ".", "update_buffer", ".", "shuffle", "(", ")", "batch_losses", "=", "[", "]", "num_batches", "=", "min", "(", "len", "(", "self", ".", "demonstration_buffer", ".", "update_b...
Updates the policy.
[ "Updates", "the", "policy", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/bc/trainer.py#L152-L171
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_global_steps
def create_global_steps(): """Creates TF ops to track and increment global training step.""" global_step = tf.Variable(0, name="global_step", trainable=False, dtype=tf.int32) increment_step = tf.assign(global_step, tf.add(global_step, 1)) return global_step, increment_step
python
def create_global_steps(): """Creates TF ops to track and increment global training step.""" global_step = tf.Variable(0, name="global_step", trainable=False, dtype=tf.int32) increment_step = tf.assign(global_step, tf.add(global_step, 1)) return global_step, increment_step
[ "def", "create_global_steps", "(", ")", ":", "global_step", "=", "tf", ".", "Variable", "(", "0", ",", "name", "=", "\"global_step\"", ",", "trainable", "=", "False", ",", "dtype", "=", "tf", ".", "int32", ")", "increment_step", "=", "tf", ".", "assign",...
Creates TF ops to track and increment global training step.
[ "Creates", "TF", "ops", "to", "track", "and", "increment", "global", "training", "step", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L43-L47
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_visual_input
def create_visual_input(camera_parameters, name): """ Creates image input op. :param camera_parameters: Parameters for visual observation from BrainInfo. :param name: Desired name of input op. :return: input op. """ o_size_h = camera_parameters['height'] o...
python
def create_visual_input(camera_parameters, name): """ Creates image input op. :param camera_parameters: Parameters for visual observation from BrainInfo. :param name: Desired name of input op. :return: input op. """ o_size_h = camera_parameters['height'] o...
[ "def", "create_visual_input", "(", "camera_parameters", ",", "name", ")", ":", "o_size_h", "=", "camera_parameters", "[", "'height'", "]", "o_size_w", "=", "camera_parameters", "[", "'width'", "]", "bw", "=", "camera_parameters", "[", "'blackAndWhite'", "]", "if",...
Creates image input op. :param camera_parameters: Parameters for visual observation from BrainInfo. :param name: Desired name of input op. :return: input op.
[ "Creates", "image", "input", "op", ".", ":", "param", "camera_parameters", ":", "Parameters", "for", "visual", "observation", "from", "BrainInfo", ".", ":", "param", "name", ":", "Desired", "name", "of", "input", "op", ".", ":", "return", ":", "input", "op...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L55-L73
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_vector_input
def create_vector_input(self, name='vector_observation'): """ Creates ops for vector observation input. :param name: Name of the placeholder op. :param vec_obs_size: Size of stacked vector observation. :return: """ self.vector_in = tf.placeholder(shape=[None, self...
python
def create_vector_input(self, name='vector_observation'): """ Creates ops for vector observation input. :param name: Name of the placeholder op. :param vec_obs_size: Size of stacked vector observation. :return: """ self.vector_in = tf.placeholder(shape=[None, self...
[ "def", "create_vector_input", "(", "self", ",", "name", "=", "'vector_observation'", ")", ":", "self", ".", "vector_in", "=", "tf", ".", "placeholder", "(", "shape", "=", "[", "None", ",", "self", ".", "vec_obs_size", "]", ",", "dtype", "=", "tf", ".", ...
Creates ops for vector observation input. :param name: Name of the placeholder op. :param vec_obs_size: Size of stacked vector observation. :return:
[ "Creates", "ops", "for", "vector", "observation", "input", ".", ":", "param", "name", ":", "Name", "of", "the", "placeholder", "op", ".", ":", "param", "vec_obs_size", ":", "Size", "of", "stacked", "vector", "observation", ".", ":", "return", ":" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L75-L99
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_vector_observation_encoder
def create_vector_observation_encoder(observation_input, h_size, activation, num_layers, scope, reuse): """ Builds a set of hidden state encoders. :param reuse: Whether to re-use the weights within the same scope. :param scope: Graph scope for th...
python
def create_vector_observation_encoder(observation_input, h_size, activation, num_layers, scope, reuse): """ Builds a set of hidden state encoders. :param reuse: Whether to re-use the weights within the same scope. :param scope: Graph scope for th...
[ "def", "create_vector_observation_encoder", "(", "observation_input", ",", "h_size", ",", "activation", ",", "num_layers", ",", "scope", ",", "reuse", ")", ":", "with", "tf", ".", "variable_scope", "(", "scope", ")", ":", "hidden", "=", "observation_input", "for...
Builds a set of hidden state encoders. :param reuse: Whether to re-use the weights within the same scope. :param scope: Graph scope for the encoder ops. :param observation_input: Input vector. :param h_size: Hidden layer size. :param activation: What type of activation function t...
[ "Builds", "a", "set", "of", "hidden", "state", "encoders", ".", ":", "param", "reuse", ":", "Whether", "to", "re", "-", "use", "the", "weights", "within", "the", "same", "scope", ".", ":", "param", "scope", ":", "Graph", "scope", "for", "the", "encoder...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L112-L131
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_visual_observation_encoder
def create_visual_observation_encoder(self, image_input, h_size, activation, num_layers, scope, reuse): """ Builds a set of visual (CNN) encoders. :param reuse: Whether to re-use the weights within the same scope. :param scope: The scope of the g...
python
def create_visual_observation_encoder(self, image_input, h_size, activation, num_layers, scope, reuse): """ Builds a set of visual (CNN) encoders. :param reuse: Whether to re-use the weights within the same scope. :param scope: The scope of the g...
[ "def", "create_visual_observation_encoder", "(", "self", ",", "image_input", ",", "h_size", ",", "activation", ",", "num_layers", ",", "scope", ",", "reuse", ")", ":", "with", "tf", ".", "variable_scope", "(", "scope", ")", ":", "conv1", "=", "tf", ".", "l...
Builds a set of visual (CNN) encoders. :param reuse: Whether to re-use the weights within the same scope. :param scope: The scope of the graph within which to create the ops. :param image_input: The placeholder for the image input to use. :param h_size: Hidden layer size. :param ...
[ "Builds", "a", "set", "of", "visual", "(", "CNN", ")", "encoders", ".", ":", "param", "reuse", ":", "Whether", "to", "re", "-", "use", "the", "weights", "within", "the", "same", "scope", ".", ":", "param", "scope", ":", "The", "scope", "of", "the", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L133-L155
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_discrete_action_masking_layer
def create_discrete_action_masking_layer(all_logits, action_masks, action_size): """ Creates a masking layer for the discrete actions :param all_logits: The concatenated unnormalized action probabilities for all branches :param action_masks: The mask for the logits. Must be of dimension ...
python
def create_discrete_action_masking_layer(all_logits, action_masks, action_size): """ Creates a masking layer for the discrete actions :param all_logits: The concatenated unnormalized action probabilities for all branches :param action_masks: The mask for the logits. Must be of dimension ...
[ "def", "create_discrete_action_masking_layer", "(", "all_logits", ",", "action_masks", ",", "action_size", ")", ":", "action_idx", "=", "[", "0", "]", "+", "list", "(", "np", ".", "cumsum", "(", "action_size", ")", ")", "branches_logits", "=", "[", "all_logits...
Creates a masking layer for the discrete actions :param all_logits: The concatenated unnormalized action probabilities for all branches :param action_masks: The mask for the logits. Must be of dimension [None x total_number_of_action] :param action_size: A list containing the number of possible ...
[ "Creates", "a", "masking", "layer", "for", "the", "discrete", "actions", ":", "param", "all_logits", ":", "The", "concatenated", "unnormalized", "action", "probabilities", "for", "all", "branches", ":", "param", "action_masks", ":", "The", "mask", "for", "the", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L158-L175
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_observation_streams
def create_observation_streams(self, num_streams, h_size, num_layers): """ Creates encoding stream for observations. :param num_streams: Number of streams to create. :param h_size: Size of hidden linear layers in stream. :param num_layers: Number of hidden linear layers in stream...
python
def create_observation_streams(self, num_streams, h_size, num_layers): """ Creates encoding stream for observations. :param num_streams: Number of streams to create. :param h_size: Size of hidden linear layers in stream. :param num_layers: Number of hidden linear layers in stream...
[ "def", "create_observation_streams", "(", "self", ",", "num_streams", ",", "h_size", ",", "num_layers", ")", ":", "brain", "=", "self", ".", "brain", "activation_fn", "=", "self", ".", "swish", "self", ".", "visual_in", "=", "[", "]", "for", "i", "in", "...
Creates encoding stream for observations. :param num_streams: Number of streams to create. :param h_size: Size of hidden linear layers in stream. :param num_layers: Number of hidden linear layers in stream. :return: List of encoded streams.
[ "Creates", "encoding", "stream", "for", "observations", ".", ":", "param", "num_streams", ":", "Number", "of", "streams", "to", "create", ".", ":", "param", "h_size", ":", "Size", "of", "hidden", "linear", "layers", "in", "stream", ".", ":", "param", "num_...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L177-L225
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_recurrent_encoder
def create_recurrent_encoder(input_state, memory_in, sequence_length, name='lstm'): """ Builds a recurrent encoder for either state or observations (LSTM). :param sequence_length: Length of sequence to unroll. :param input_state: The input tensor to the LSTM cell. :param memory_i...
python
def create_recurrent_encoder(input_state, memory_in, sequence_length, name='lstm'): """ Builds a recurrent encoder for either state or observations (LSTM). :param sequence_length: Length of sequence to unroll. :param input_state: The input tensor to the LSTM cell. :param memory_i...
[ "def", "create_recurrent_encoder", "(", "input_state", ",", "memory_in", ",", "sequence_length", ",", "name", "=", "'lstm'", ")", ":", "s_size", "=", "input_state", ".", "get_shape", "(", ")", ".", "as_list", "(", ")", "[", "1", "]", "m_size", "=", "memory...
Builds a recurrent encoder for either state or observations (LSTM). :param sequence_length: Length of sequence to unroll. :param input_state: The input tensor to the LSTM cell. :param memory_in: The input memory to the LSTM cell. :param name: The scope of the LSTM cell.
[ "Builds", "a", "recurrent", "encoder", "for", "either", "state", "or", "observations", "(", "LSTM", ")", ".", ":", "param", "sequence_length", ":", "Length", "of", "sequence", "to", "unroll", ".", ":", "param", "input_state", ":", "The", "input", "tensor", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L228-L249
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_cc_actor_critic
def create_cc_actor_critic(self, h_size, num_layers): """ Creates Continuous control actor-critic model. :param h_size: Size of hidden linear layers. :param num_layers: Number of hidden linear layers. """ hidden_streams = self.create_observation_streams(2, h_size, num_lay...
python
def create_cc_actor_critic(self, h_size, num_layers): """ Creates Continuous control actor-critic model. :param h_size: Size of hidden linear layers. :param num_layers: Number of hidden linear layers. """ hidden_streams = self.create_observation_streams(2, h_size, num_lay...
[ "def", "create_cc_actor_critic", "(", "self", ",", "h_size", ",", "num_layers", ")", ":", "hidden_streams", "=", "self", ".", "create_observation_streams", "(", "2", ",", "h_size", ",", "num_layers", ")", "if", "self", ".", "use_recurrent", ":", "self", ".", ...
Creates Continuous control actor-critic model. :param h_size: Size of hidden linear layers. :param num_layers: Number of hidden linear layers.
[ "Creates", "Continuous", "control", "actor", "-", "critic", "model", ".", ":", "param", "h_size", ":", "Size", "of", "hidden", "linear", "layers", ".", ":", "param", "num_layers", ":", "Number", "of", "hidden", "linear", "layers", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L251-L308
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/models.py
LearningModel.create_dc_actor_critic
def create_dc_actor_critic(self, h_size, num_layers): """ Creates Discrete control actor-critic model. :param h_size: Size of hidden linear layers. :param num_layers: Number of hidden linear layers. """ hidden_streams = self.create_observation_streams(1, h_size, num_layer...
python
def create_dc_actor_critic(self, h_size, num_layers): """ Creates Discrete control actor-critic model. :param h_size: Size of hidden linear layers. :param num_layers: Number of hidden linear layers. """ hidden_streams = self.create_observation_streams(1, h_size, num_layer...
[ "def", "create_dc_actor_critic", "(", "self", ",", "h_size", ",", "num_layers", ")", ":", "hidden_streams", "=", "self", ".", "create_observation_streams", "(", "1", ",", "h_size", ",", "num_layers", ")", "hidden", "=", "hidden_streams", "[", "0", "]", "if", ...
Creates Discrete control actor-critic model. :param h_size: Size of hidden linear layers. :param num_layers: Number of hidden linear layers.
[ "Creates", "Discrete", "control", "actor", "-", "critic", "model", ".", ":", "param", "h_size", ":", "Size", "of", "hidden", "linear", "layers", ".", ":", "param", "num_layers", ":", "Number", "of", "hidden", "linear", "layers", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/models.py#L310-L380
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/bc/online_trainer.py
OnlineBCTrainer.add_experiences
def add_experiences(self, curr_info: AllBrainInfo, next_info: AllBrainInfo, take_action_outputs): """ Adds experiences to each agent's experience history. :param curr_info: Current AllBrainInfo (Dictionary of all current brains and corresponding BrainInfo). :param...
python
def add_experiences(self, curr_info: AllBrainInfo, next_info: AllBrainInfo, take_action_outputs): """ Adds experiences to each agent's experience history. :param curr_info: Current AllBrainInfo (Dictionary of all current brains and corresponding BrainInfo). :param...
[ "def", "add_experiences", "(", "self", ",", "curr_info", ":", "AllBrainInfo", ",", "next_info", ":", "AllBrainInfo", ",", "take_action_outputs", ")", ":", "# Used to collect teacher experience into training buffer", "info_teacher", "=", "curr_info", "[", "self", ".", "b...
Adds experiences to each agent's experience history. :param curr_info: Current AllBrainInfo (Dictionary of all current brains and corresponding BrainInfo). :param next_info: Next AllBrainInfo (Dictionary of all current brains and corresponding BrainInfo). :param take_action_outputs: The outputs ...
[ "Adds", "experiences", "to", "each", "agent", "s", "experience", "history", ".", ":", "param", "curr_info", ":", "Current", "AllBrainInfo", "(", "Dictionary", "of", "all", "current", "brains", "and", "corresponding", "BrainInfo", ")", ".", ":", "param", "next_...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/bc/online_trainer.py#L47-L97
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/bc/online_trainer.py
OnlineBCTrainer.process_experiences
def process_experiences(self, current_info: AllBrainInfo, next_info: AllBrainInfo): """ Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Current AllB...
python
def process_experiences(self, current_info: AllBrainInfo, next_info: AllBrainInfo): """ Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Current AllB...
[ "def", "process_experiences", "(", "self", ",", "current_info", ":", "AllBrainInfo", ",", "next_info", ":", "AllBrainInfo", ")", ":", "info_teacher", "=", "next_info", "[", "self", ".", "brain_to_imitate", "]", "for", "l", "in", "range", "(", "len", "(", "in...
Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Current AllBrainInfo :param next_info: Next AllBrainInfo
[ "Checks", "agent", "histories", "for", "processing", "condition", "and", "processes", "them", "as", "necessary", ".", "Processing", "involves", "calculating", "value", "and", "advantage", "targets", "for", "model", "updating", "step", ".", ":", "param", "current_i...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/bc/online_trainer.py#L99-L117
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/tensorflow_to_barracuda.py
flatten
def flatten(items,enter=lambda x:isinstance(x, list)): # http://stackoverflow.com/a/40857703 # https://github.com/ctmakro/canton/blob/master/canton/misc.py """Yield items from any nested iterable; see REF.""" for x in items: if enter(x): yield from flatten(x) else: ...
python
def flatten(items,enter=lambda x:isinstance(x, list)): # http://stackoverflow.com/a/40857703 # https://github.com/ctmakro/canton/blob/master/canton/misc.py """Yield items from any nested iterable; see REF.""" for x in items: if enter(x): yield from flatten(x) else: ...
[ "def", "flatten", "(", "items", ",", "enter", "=", "lambda", "x", ":", "isinstance", "(", "x", ",", "list", ")", ")", ":", "# http://stackoverflow.com/a/40857703", "# https://github.com/ctmakro/canton/blob/master/canton/misc.py", "for", "x", "in", "items", ":", "if"...
Yield items from any nested iterable; see REF.
[ "Yield", "items", "from", "any", "nested", "iterable", ";", "see", "REF", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/tensorflow_to_barracuda.py#L496-L504
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/tensorflow_to_barracuda.py
replace_strings_in_list
def replace_strings_in_list(array_of_strigs, replace_with_strings): "A value in replace_with_strings can be either single string or list of strings" potentially_nested_list = [replace_with_strings.get(s) or s for s in array_of_strigs] return list(flatten(potentially_nested_list))
python
def replace_strings_in_list(array_of_strigs, replace_with_strings): "A value in replace_with_strings can be either single string or list of strings" potentially_nested_list = [replace_with_strings.get(s) or s for s in array_of_strigs] return list(flatten(potentially_nested_list))
[ "def", "replace_strings_in_list", "(", "array_of_strigs", ",", "replace_with_strings", ")", ":", "potentially_nested_list", "=", "[", "replace_with_strings", ".", "get", "(", "s", ")", "or", "s", "for", "s", "in", "array_of_strigs", "]", "return", "list", "(", "...
A value in replace_with_strings can be either single string or list of strings
[ "A", "value", "in", "replace_with_strings", "can", "be", "either", "single", "string", "or", "list", "of", "strings" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/tensorflow_to_barracuda.py#L506-L509
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/tensorflow_to_barracuda.py
remove_duplicates_from_list
def remove_duplicates_from_list(array): "Preserves the order of elements in the list" output = [] unique = set() for a in array: if a not in unique: unique.add(a) output.append(a) return output
python
def remove_duplicates_from_list(array): "Preserves the order of elements in the list" output = [] unique = set() for a in array: if a not in unique: unique.add(a) output.append(a) return output
[ "def", "remove_duplicates_from_list", "(", "array", ")", ":", "output", "=", "[", "]", "unique", "=", "set", "(", ")", "for", "a", "in", "array", ":", "if", "a", "not", "in", "unique", ":", "unique", ".", "add", "(", "a", ")", "output", ".", "appen...
Preserves the order of elements in the list
[ "Preserves", "the", "order", "of", "elements", "in", "the", "list" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/tensorflow_to_barracuda.py#L511-L519
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/tensorflow_to_barracuda.py
pool_to_HW
def pool_to_HW(shape, data_frmt): """ Convert from NHWC|NCHW => HW """ if len(shape) != 4: return shape # Not NHWC|NCHW, return as is if data_frmt == 'NCHW': return [shape[2], shape[3]] return [shape[1], shape[2]]
python
def pool_to_HW(shape, data_frmt): """ Convert from NHWC|NCHW => HW """ if len(shape) != 4: return shape # Not NHWC|NCHW, return as is if data_frmt == 'NCHW': return [shape[2], shape[3]] return [shape[1], shape[2]]
[ "def", "pool_to_HW", "(", "shape", ",", "data_frmt", ")", ":", "if", "len", "(", "shape", ")", "!=", "4", ":", "return", "shape", "# Not NHWC|NCHW, return as is", "if", "data_frmt", "==", "'NCHW'", ":", "return", "[", "shape", "[", "2", "]", ",", "shape"...
Convert from NHWC|NCHW => HW
[ "Convert", "from", "NHWC|NCHW", "=", ">", "HW" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/tensorflow_to_barracuda.py#L523-L530
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/tensorflow_to_barracuda.py
convert
def convert(source_file, target_file, trim_unused_by_output="", verbose=False, compress_f16=False): """ Converts a TensorFlow model into a Barracuda model. :param source_file: The TensorFlow Model :param target_file: The name of the file the converted model will be saved to :param trim_unused_by_out...
python
def convert(source_file, target_file, trim_unused_by_output="", verbose=False, compress_f16=False): """ Converts a TensorFlow model into a Barracuda model. :param source_file: The TensorFlow Model :param target_file: The name of the file the converted model will be saved to :param trim_unused_by_out...
[ "def", "convert", "(", "source_file", ",", "target_file", ",", "trim_unused_by_output", "=", "\"\"", ",", "verbose", "=", "False", ",", "compress_f16", "=", "False", ")", ":", "if", "(", "type", "(", "verbose", ")", "==", "bool", ")", ":", "args", "=", ...
Converts a TensorFlow model into a Barracuda model. :param source_file: The TensorFlow Model :param target_file: The name of the file the converted model will be saved to :param trim_unused_by_output: The regexp to match output nodes to remain in the model. All other uconnected nodes will be removed. :p...
[ "Converts", "a", "TensorFlow", "model", "into", "a", "Barracuda", "model", ".", ":", "param", "source_file", ":", "The", "TensorFlow", "Model", ":", "param", "target_file", ":", "The", "name", "of", "the", "file", "the", "converted", "model", "will", "be", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/tensorflow_to_barracuda.py#L901-L1034
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/demo_loader.py
demo_to_buffer
def demo_to_buffer(file_path, sequence_length): """ Loads demonstration file and uses it to fill training buffer. :param file_path: Location of demonstration file (.demo). :param sequence_length: Length of trajectories to fill buffer. :return: """ brain_params, brain_infos, _ = load_demonstr...
python
def demo_to_buffer(file_path, sequence_length): """ Loads demonstration file and uses it to fill training buffer. :param file_path: Location of demonstration file (.demo). :param sequence_length: Length of trajectories to fill buffer. :return: """ brain_params, brain_infos, _ = load_demonstr...
[ "def", "demo_to_buffer", "(", "file_path", ",", "sequence_length", ")", ":", "brain_params", ",", "brain_infos", ",", "_", "=", "load_demonstration", "(", "file_path", ")", "demo_buffer", "=", "make_demo_buffer", "(", "brain_infos", ",", "brain_params", ",", "sequ...
Loads demonstration file and uses it to fill training buffer. :param file_path: Location of demonstration file (.demo). :param sequence_length: Length of trajectories to fill buffer. :return:
[ "Loads", "demonstration", "file", "and", "uses", "it", "to", "fill", "training", "buffer", ".", ":", "param", "file_path", ":", "Location", "of", "demonstration", "file", "(", ".", "demo", ")", ".", ":", "param", "sequence_length", ":", "Length", "of", "tr...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/demo_loader.py#L39-L48
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/demo_loader.py
load_demonstration
def load_demonstration(file_path): """ Loads and parses a demonstration file. :param file_path: Location of demonstration file (.demo). :return: BrainParameter and list of BrainInfos containing demonstration data. """ # First 32 bytes of file dedicated to meta-data. INITIAL_POS = 33 if...
python
def load_demonstration(file_path): """ Loads and parses a demonstration file. :param file_path: Location of demonstration file (.demo). :return: BrainParameter and list of BrainInfos containing demonstration data. """ # First 32 bytes of file dedicated to meta-data. INITIAL_POS = 33 if...
[ "def", "load_demonstration", "(", "file_path", ")", ":", "# First 32 bytes of file dedicated to meta-data.", "INITIAL_POS", "=", "33", "if", "not", "os", ".", "path", ".", "isfile", "(", "file_path", ")", ":", "raise", "FileNotFoundError", "(", "\"The demonstration fi...
Loads and parses a demonstration file. :param file_path: Location of demonstration file (.demo). :return: BrainParameter and list of BrainInfos containing demonstration data.
[ "Loads", "and", "parses", "a", "demonstration", "file", ".", ":", "param", "file_path", ":", "Location", "of", "demonstration", "file", "(", ".", "demo", ")", ".", ":", "return", ":", "BrainParameter", "and", "list", "of", "BrainInfos", "containing", "demons...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/demo_loader.py#L51-L94
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_controller.py
TrainerController._save_model
def _save_model(self, steps=0): """ Saves current model to checkpoint folder. :param steps: Current number of steps in training process. :param saver: Tensorflow saver for session. """ for brain_name in self.trainers.keys(): self.trainers[brain_name].save_mode...
python
def _save_model(self, steps=0): """ Saves current model to checkpoint folder. :param steps: Current number of steps in training process. :param saver: Tensorflow saver for session. """ for brain_name in self.trainers.keys(): self.trainers[brain_name].save_mode...
[ "def", "_save_model", "(", "self", ",", "steps", "=", "0", ")", ":", "for", "brain_name", "in", "self", ".", "trainers", ".", "keys", "(", ")", ":", "self", ".", "trainers", "[", "brain_name", "]", ".", "save_model", "(", ")", "self", ".", "logger", ...
Saves current model to checkpoint folder. :param steps: Current number of steps in training process. :param saver: Tensorflow saver for session.
[ "Saves", "current", "model", "to", "checkpoint", "folder", ".", ":", "param", "steps", ":", "Current", "number", "of", "steps", "in", "training", "process", ".", ":", "param", "saver", ":", "Tensorflow", "saver", "for", "session", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_controller.py#L91-L99
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_controller.py
TrainerController._write_training_metrics
def _write_training_metrics(self): """ Write all CSV metrics :return: """ for brain_name in self.trainers.keys(): if brain_name in self.trainer_metrics: self.trainers[brain_name].write_training_metrics()
python
def _write_training_metrics(self): """ Write all CSV metrics :return: """ for brain_name in self.trainers.keys(): if brain_name in self.trainer_metrics: self.trainers[brain_name].write_training_metrics()
[ "def", "_write_training_metrics", "(", "self", ")", ":", "for", "brain_name", "in", "self", ".", "trainers", ".", "keys", "(", ")", ":", "if", "brain_name", "in", "self", ".", "trainer_metrics", ":", "self", ".", "trainers", "[", "brain_name", "]", ".", ...
Write all CSV metrics :return:
[ "Write", "all", "CSV", "metrics", ":", "return", ":" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_controller.py#L106-L113
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_controller.py
TrainerController._export_graph
def _export_graph(self): """ Exports latest saved models to .nn format for Unity embedding. """ for brain_name in self.trainers.keys(): self.trainers[brain_name].export_model()
python
def _export_graph(self): """ Exports latest saved models to .nn format for Unity embedding. """ for brain_name in self.trainers.keys(): self.trainers[brain_name].export_model()
[ "def", "_export_graph", "(", "self", ")", ":", "for", "brain_name", "in", "self", ".", "trainers", ".", "keys", "(", ")", ":", "self", ".", "trainers", "[", "brain_name", "]", ".", "export_model", "(", ")" ]
Exports latest saved models to .nn format for Unity embedding.
[ "Exports", "latest", "saved", "models", "to", ".", "nn", "format", "for", "Unity", "embedding", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_controller.py#L115-L120
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_controller.py
TrainerController.initialize_trainers
def initialize_trainers(self, trainer_config: Dict[str, Dict[str, str]]): """ Initialization of the trainers :param trainer_config: The configurations of the trainers """ trainer_parameters_dict = {} for brain_name in self.external_brains: trainer_parameters =...
python
def initialize_trainers(self, trainer_config: Dict[str, Dict[str, str]]): """ Initialization of the trainers :param trainer_config: The configurations of the trainers """ trainer_parameters_dict = {} for brain_name in self.external_brains: trainer_parameters =...
[ "def", "initialize_trainers", "(", "self", ",", "trainer_config", ":", "Dict", "[", "str", ",", "Dict", "[", "str", ",", "str", "]", "]", ")", ":", "trainer_parameters_dict", "=", "{", "}", "for", "brain_name", "in", "self", ".", "external_brains", ":", ...
Initialization of the trainers :param trainer_config: The configurations of the trainers
[ "Initialization", "of", "the", "trainers", ":", "param", "trainer_config", ":", "The", "configurations", "of", "the", "trainers" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_controller.py#L122-L169
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/trainer_controller.py
TrainerController._reset_env
def _reset_env(self, env: BaseUnityEnvironment): """Resets the environment. Returns: A Data structure corresponding to the initial reset state of the environment. """ if self.meta_curriculum is not None: return env.reset(train_mode=self.fast_simulatio...
python
def _reset_env(self, env: BaseUnityEnvironment): """Resets the environment. Returns: A Data structure corresponding to the initial reset state of the environment. """ if self.meta_curriculum is not None: return env.reset(train_mode=self.fast_simulatio...
[ "def", "_reset_env", "(", "self", ",", "env", ":", "BaseUnityEnvironment", ")", ":", "if", "self", ".", "meta_curriculum", "is", "not", "None", ":", "return", "env", ".", "reset", "(", "train_mode", "=", "self", ".", "fast_simulation", ",", "config", "=", ...
Resets the environment. Returns: A Data structure corresponding to the initial reset state of the environment.
[ "Resets", "the", "environment", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/trainer_controller.py#L183-L193
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/socket_communicator.py
SocketCommunicator.close
def close(self): """ Sends a shutdown signal to the unity environment, and closes the socket connection. """ if self._socket is not None and self._conn is not None: message_input = UnityMessage() message_input.header.status = 400 self._communicator_sen...
python
def close(self): """ Sends a shutdown signal to the unity environment, and closes the socket connection. """ if self._socket is not None and self._conn is not None: message_input = UnityMessage() message_input.header.status = 400 self._communicator_sen...
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "_socket", "is", "not", "None", "and", "self", ".", "_conn", "is", "not", "None", ":", "message_input", "=", "UnityMessage", "(", ")", "message_input", ".", "header", ".", "status", "=", "400", ...
Sends a shutdown signal to the unity environment, and closes the socket connection.
[ "Sends", "a", "shutdown", "signal", "to", "the", "unity", "environment", "and", "closes", "the", "socket", "connection", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/socket_communicator.py#L84-L97
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/barracuda.py
fuse_batchnorm_weights
def fuse_batchnorm_weights(gamma, beta, mean, var, epsilon): # https://github.com/Tencent/ncnn/blob/master/src/layer/batchnorm.cpp """ float sqrt_var = sqrt(var_data[i]); a_data[i] = bias_data[i] - slope_data[i] * mean_data[i] / sqrt_var; b_data[i] = slope_data[i] / sqrt_var; ... ...
python
def fuse_batchnorm_weights(gamma, beta, mean, var, epsilon): # https://github.com/Tencent/ncnn/blob/master/src/layer/batchnorm.cpp """ float sqrt_var = sqrt(var_data[i]); a_data[i] = bias_data[i] - slope_data[i] * mean_data[i] / sqrt_var; b_data[i] = slope_data[i] / sqrt_var; ... ...
[ "def", "fuse_batchnorm_weights", "(", "gamma", ",", "beta", ",", "mean", ",", "var", ",", "epsilon", ")", ":", "# https://github.com/Tencent/ncnn/blob/master/src/layer/batchnorm.cpp", "scale", "=", "gamma", "/", "np", ".", "sqrt", "(", "var", "+", "epsilon", ")", ...
float sqrt_var = sqrt(var_data[i]); a_data[i] = bias_data[i] - slope_data[i] * mean_data[i] / sqrt_var; b_data[i] = slope_data[i] / sqrt_var; ... ptr[i] = b * ptr[i] + a;
[ "float", "sqrt_var", "=", "sqrt", "(", "var_data", "[", "i", "]", ")", ";", "a_data", "[", "i", "]", "=", "bias_data", "[", "i", "]", "-", "slope_data", "[", "i", "]", "*", "mean_data", "[", "i", "]", "/", "sqrt_var", ";", "b_data", "[", "i", "...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/barracuda.py#L63-L73
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/barracuda.py
rnn
def rnn(name, input, state, kernel, bias, new_state, number_of_gates = 2): ''' - Ht = f(Xt*Wi + Ht_1*Ri + Wbi + Rbi) ''' nn = Build(name) nn.tanh( nn.mad(kernel=kernel, bias=bias, x=nn.concat(input, state)), out=new_state); return nn.layers;
python
def rnn(name, input, state, kernel, bias, new_state, number_of_gates = 2): ''' - Ht = f(Xt*Wi + Ht_1*Ri + Wbi + Rbi) ''' nn = Build(name) nn.tanh( nn.mad(kernel=kernel, bias=bias, x=nn.concat(input, state)), out=new_state); return nn.layers;
[ "def", "rnn", "(", "name", ",", "input", ",", "state", ",", "kernel", ",", "bias", ",", "new_state", ",", "number_of_gates", "=", "2", ")", ":", "nn", "=", "Build", "(", "name", ")", "nn", ".", "tanh", "(", "nn", ".", "mad", "(", "kernel", "=", ...
- Ht = f(Xt*Wi + Ht_1*Ri + Wbi + Rbi)
[ "-", "Ht", "=", "f", "(", "Xt", "*", "Wi", "+", "Ht_1", "*", "Ri", "+", "Wbi", "+", "Rbi", ")" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/barracuda.py#L309-L318
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/barracuda.py
gru
def gru(name, input, state, kernel_r, kernel_u, kernel_c, bias_r, bias_u, bias_c, new_state, number_of_gates = 2): ''' - zt = f(Xt*Wz + Ht_1*Rz + Wbz + Rbz) - rt = f(Xt*Wr + Ht_1*Rr + Wbr + Rbr) - ht = g(Xt*Wh + (rt . Ht_1)*Rh + Rbh + Wbh) - Ht = (1-zt).ht + zt.Ht_1 ''' ...
python
def gru(name, input, state, kernel_r, kernel_u, kernel_c, bias_r, bias_u, bias_c, new_state, number_of_gates = 2): ''' - zt = f(Xt*Wz + Ht_1*Rz + Wbz + Rbz) - rt = f(Xt*Wr + Ht_1*Rr + Wbr + Rbr) - ht = g(Xt*Wh + (rt . Ht_1)*Rh + Rbh + Wbh) - Ht = (1-zt).ht + zt.Ht_1 ''' ...
[ "def", "gru", "(", "name", ",", "input", ",", "state", ",", "kernel_r", ",", "kernel_u", ",", "kernel_c", ",", "bias_r", ",", "bias_u", ",", "bias_c", ",", "new_state", ",", "number_of_gates", "=", "2", ")", ":", "nn", "=", "Build", "(", "name", ")",...
- zt = f(Xt*Wz + Ht_1*Rz + Wbz + Rbz) - rt = f(Xt*Wr + Ht_1*Rr + Wbr + Rbr) - ht = g(Xt*Wh + (rt . Ht_1)*Rh + Rbh + Wbh) - Ht = (1-zt).ht + zt.Ht_1
[ "-", "zt", "=", "f", "(", "Xt", "*", "Wz", "+", "Ht_1", "*", "Rz", "+", "Wbz", "+", "Rbz", ")", "-", "rt", "=", "f", "(", "Xt", "*", "Wr", "+", "Ht_1", "*", "Rr", "+", "Wbr", "+", "Rbr", ")", "-", "ht", "=", "g", "(", "Xt", "*", "Wh",...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/barracuda.py#L320-L345
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/barracuda.py
lstm
def lstm(name, input, state_c, state_h, kernel_i, kernel_j, kernel_f, kernel_o, bias_i, bias_j, bias_f, bias_o, new_state_c, new_state_h): ''' Full: - it = f(Xt*Wi + Ht_1*Ri + Pi . Ct_1 + Wbi + Rbi) - ft = f(Xt*Wf + Ht_1*Rf + Pf . Ct_1 + Wbf + Rbf) - ct = g(Xt*Wc + Ht_1*Rc + Wbc + Rbc) - Ct = ft . ...
python
def lstm(name, input, state_c, state_h, kernel_i, kernel_j, kernel_f, kernel_o, bias_i, bias_j, bias_f, bias_o, new_state_c, new_state_h): ''' Full: - it = f(Xt*Wi + Ht_1*Ri + Pi . Ct_1 + Wbi + Rbi) - ft = f(Xt*Wf + Ht_1*Rf + Pf . Ct_1 + Wbf + Rbf) - ct = g(Xt*Wc + Ht_1*Rc + Wbc + Rbc) - Ct = ft . ...
[ "def", "lstm", "(", "name", ",", "input", ",", "state_c", ",", "state_h", ",", "kernel_i", ",", "kernel_j", ",", "kernel_f", ",", "kernel_o", ",", "bias_i", ",", "bias_j", ",", "bias_f", ",", "bias_o", ",", "new_state_c", ",", "new_state_h", ")", ":", ...
Full: - it = f(Xt*Wi + Ht_1*Ri + Pi . Ct_1 + Wbi + Rbi) - ft = f(Xt*Wf + Ht_1*Rf + Pf . Ct_1 + Wbf + Rbf) - ct = g(Xt*Wc + Ht_1*Rc + Wbc + Rbc) - Ct = ft . Ct_1 + it . ct - ot = f(Xt*Wo + Ht_1*Ro + Po . Ct + Wbo + Rbo) - Ht = ot . h(Ct)
[ "Full", ":", "-", "it", "=", "f", "(", "Xt", "*", "Wi", "+", "Ht_1", "*", "Ri", "+", "Pi", ".", "Ct_1", "+", "Wbi", "+", "Rbi", ")", "-", "ft", "=", "f", "(", "Xt", "*", "Wf", "+", "Ht_1", "*", "Rf", "+", "Pf", ".", "Ct_1", "+", "Wbf", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/barracuda.py#L347-L383
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/bc/policy.py
BCPolicy.evaluate
def evaluate(self, brain_info): """ Evaluates policy for the agent experiences provided. :param brain_info: BrainInfo input to network. :return: Results of evaluation. """ feed_dict = {self.model.dropout_rate: self.evaluate_rate, self.model.sequence_l...
python
def evaluate(self, brain_info): """ Evaluates policy for the agent experiences provided. :param brain_info: BrainInfo input to network. :return: Results of evaluation. """ feed_dict = {self.model.dropout_rate: self.evaluate_rate, self.model.sequence_l...
[ "def", "evaluate", "(", "self", ",", "brain_info", ")", ":", "feed_dict", "=", "{", "self", ".", "model", ".", "dropout_rate", ":", "self", ".", "evaluate_rate", ",", "self", ".", "model", ".", "sequence_length", ":", "1", "}", "feed_dict", "=", "self", ...
Evaluates policy for the agent experiences provided. :param brain_info: BrainInfo input to network. :return: Results of evaluation.
[ "Evaluates", "policy", "for", "the", "agent", "experiences", "provided", ".", ":", "param", "brain_info", ":", "BrainInfo", "input", "to", "network", ".", ":", "return", ":", "Results", "of", "evaluation", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/bc/policy.py#L46-L61
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/bc/policy.py
BCPolicy.update
def update(self, mini_batch, num_sequences): """ Performs update on model. :param mini_batch: Batch of experiences. :param num_sequences: Number of sequences to process. :return: Results of update. """ feed_dict = {self.model.dropout_rate: self.update_rate, ...
python
def update(self, mini_batch, num_sequences): """ Performs update on model. :param mini_batch: Batch of experiences. :param num_sequences: Number of sequences to process. :return: Results of update. """ feed_dict = {self.model.dropout_rate: self.update_rate, ...
[ "def", "update", "(", "self", ",", "mini_batch", ",", "num_sequences", ")", ":", "feed_dict", "=", "{", "self", ".", "model", ".", "dropout_rate", ":", "self", ".", "update_rate", ",", "self", ".", "model", ".", "batch_size", ":", "num_sequences", ",", "...
Performs update on model. :param mini_batch: Batch of experiences. :param num_sequences: Number of sequences to process. :return: Results of update.
[ "Performs", "update", "on", "model", ".", ":", "param", "mini_batch", ":", "Batch", "of", "experiences", ".", ":", "param", "num_sequences", ":", "Number", "of", "sequences", "to", "process", ".", ":", "return", ":", "Results", "of", "update", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/bc/policy.py#L63-L93
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/curriculum.py
Curriculum.increment_lesson
def increment_lesson(self, measure_val): """ Increments the lesson number depending on the progress given. :param measure_val: Measure of progress (either reward or percentage steps completed). :return Whether the lesson was incremented. """ if not self.dat...
python
def increment_lesson(self, measure_val): """ Increments the lesson number depending on the progress given. :param measure_val: Measure of progress (either reward or percentage steps completed). :return Whether the lesson was incremented. """ if not self.dat...
[ "def", "increment_lesson", "(", "self", ",", "measure_val", ")", ":", "if", "not", "self", ".", "data", "or", "not", "measure_val", "or", "math", ".", "isnan", "(", "measure_val", ")", ":", "return", "False", "if", "self", ".", "data", "[", "'signal_smoo...
Increments the lesson number depending on the progress given. :param measure_val: Measure of progress (either reward or percentage steps completed). :return Whether the lesson was incremented.
[ "Increments", "the", "lesson", "number", "depending", "on", "the", "progress", "given", ".", ":", "param", "measure_val", ":", "Measure", "of", "progress", "(", "either", "reward", "or", "percentage", "steps", "completed", ")", ".", ":", "return", "Whether", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/curriculum.py#L69-L94
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/curriculum.py
Curriculum.get_config
def get_config(self, lesson=None): """ Returns reset parameters which correspond to the lesson. :param lesson: The lesson you want to get the config of. If None, the current lesson is returned. :return: The configuration of the reset parameters. """ if not ...
python
def get_config(self, lesson=None): """ Returns reset parameters which correspond to the lesson. :param lesson: The lesson you want to get the config of. If None, the current lesson is returned. :return: The configuration of the reset parameters. """ if not ...
[ "def", "get_config", "(", "self", ",", "lesson", "=", "None", ")", ":", "if", "not", "self", ".", "data", ":", "return", "{", "}", "if", "lesson", "is", "None", ":", "lesson", "=", "self", ".", "lesson_num", "lesson", "=", "max", "(", "0", ",", "...
Returns reset parameters which correspond to the lesson. :param lesson: The lesson you want to get the config of. If None, the current lesson is returned. :return: The configuration of the reset parameters.
[ "Returns", "reset", "parameters", "which", "correspond", "to", "the", "lesson", ".", ":", "param", "lesson", ":", "The", "lesson", "you", "want", "to", "get", "the", "config", "of", ".", "If", "None", "the", "current", "lesson", "is", "returned", ".", ":...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/curriculum.py#L96-L112
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/trainer.py
get_gae
def get_gae(rewards, value_estimates, value_next=0.0, gamma=0.99, lambd=0.95): """ Computes generalized advantage estimate for use in updating policy. :param rewards: list of rewards for time-steps t to T. :param value_next: Value estimate for time-step T+1. :param value_estimates: list of value est...
python
def get_gae(rewards, value_estimates, value_next=0.0, gamma=0.99, lambd=0.95): """ Computes generalized advantage estimate for use in updating policy. :param rewards: list of rewards for time-steps t to T. :param value_next: Value estimate for time-step T+1. :param value_estimates: list of value est...
[ "def", "get_gae", "(", "rewards", ",", "value_estimates", ",", "value_next", "=", "0.0", ",", "gamma", "=", "0.99", ",", "lambd", "=", "0.95", ")", ":", "value_estimates", "=", "np", ".", "asarray", "(", "value_estimates", ".", "tolist", "(", ")", "+", ...
Computes generalized advantage estimate for use in updating policy. :param rewards: list of rewards for time-steps t to T. :param value_next: Value estimate for time-step T+1. :param value_estimates: list of value estimates for time-steps t to T. :param gamma: Discount factor. :param lambd: GAE weig...
[ "Computes", "generalized", "advantage", "estimate", "for", "use", "in", "updating", "policy", ".", ":", "param", "rewards", ":", "list", "of", "rewards", "for", "time", "-", "steps", "t", "to", "T", ".", ":", "param", "value_next", ":", "Value", "estimate"...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/trainer.py#L364-L377
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/trainer.py
PPOTrainer.increment_step_and_update_last_reward
def increment_step_and_update_last_reward(self): """ Increment the step count of the trainer and Updates the last reward """ if len(self.stats['Environment/Cumulative Reward']) > 0: mean_reward = np.mean(self.stats['Environment/Cumulative Reward']) self.policy.upd...
python
def increment_step_and_update_last_reward(self): """ Increment the step count of the trainer and Updates the last reward """ if len(self.stats['Environment/Cumulative Reward']) > 0: mean_reward = np.mean(self.stats['Environment/Cumulative Reward']) self.policy.upd...
[ "def", "increment_step_and_update_last_reward", "(", "self", ")", ":", "if", "len", "(", "self", ".", "stats", "[", "'Environment/Cumulative Reward'", "]", ")", ">", "0", ":", "mean_reward", "=", "np", ".", "mean", "(", "self", ".", "stats", "[", "'Environme...
Increment the step count of the trainer and Updates the last reward
[ "Increment", "the", "step", "count", "of", "the", "trainer", "and", "Updates", "the", "last", "reward" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/trainer.py#L99-L107
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/trainer.py
PPOTrainer.construct_curr_info
def construct_curr_info(self, next_info: BrainInfo) -> BrainInfo: """ Constructs a BrainInfo which contains the most recent previous experiences for all agents info which correspond to the agents in a provided next_info. :BrainInfo next_info: A t+1 BrainInfo. :return: curr_info: ...
python
def construct_curr_info(self, next_info: BrainInfo) -> BrainInfo: """ Constructs a BrainInfo which contains the most recent previous experiences for all agents info which correspond to the agents in a provided next_info. :BrainInfo next_info: A t+1 BrainInfo. :return: curr_info: ...
[ "def", "construct_curr_info", "(", "self", ",", "next_info", ":", "BrainInfo", ")", "->", "BrainInfo", ":", "visual_observations", "=", "[", "[", "]", "]", "vector_observations", "=", "[", "]", "text_observations", "=", "[", "]", "memories", "=", "[", "]", ...
Constructs a BrainInfo which contains the most recent previous experiences for all agents info which correspond to the agents in a provided next_info. :BrainInfo next_info: A t+1 BrainInfo. :return: curr_info: Reconstructed BrainInfo to match agents of next_info.
[ "Constructs", "a", "BrainInfo", "which", "contains", "the", "most", "recent", "previous", "experiences", "for", "all", "agents", "info", "which", "correspond", "to", "the", "agents", "in", "a", "provided", "next_info", ".", ":", "BrainInfo", "next_info", ":", ...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/trainer.py#L109-L153
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/trainer.py
PPOTrainer.add_experiences
def add_experiences(self, curr_all_info: AllBrainInfo, next_all_info: AllBrainInfo, take_action_outputs): """ Adds experiences to each agent's experience history. :param curr_all_info: Dictionary of all current brains and corresponding BrainInfo. :param next_all_info: Dictionary of all c...
python
def add_experiences(self, curr_all_info: AllBrainInfo, next_all_info: AllBrainInfo, take_action_outputs): """ Adds experiences to each agent's experience history. :param curr_all_info: Dictionary of all current brains and corresponding BrainInfo. :param next_all_info: Dictionary of all c...
[ "def", "add_experiences", "(", "self", ",", "curr_all_info", ":", "AllBrainInfo", ",", "next_all_info", ":", "AllBrainInfo", ",", "take_action_outputs", ")", ":", "self", ".", "trainer_metrics", ".", "start_experience_collection_timer", "(", ")", "if", "take_action_ou...
Adds experiences to each agent's experience history. :param curr_all_info: Dictionary of all current brains and corresponding BrainInfo. :param next_all_info: Dictionary of all current brains and corresponding BrainInfo. :param take_action_outputs: The outputs of the Policy's get_action method.
[ "Adds", "experiences", "to", "each", "agent", "s", "experience", "history", ".", ":", "param", "curr_all_info", ":", "Dictionary", "of", "all", "current", "brains", "and", "corresponding", "BrainInfo", ".", ":", "param", "next_all_info", ":", "Dictionary", "of",...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/trainer.py#L155-L235
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/trainer.py
PPOTrainer.process_experiences
def process_experiences(self, current_info: AllBrainInfo, new_info: AllBrainInfo): """ Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Dictionary of...
python
def process_experiences(self, current_info: AllBrainInfo, new_info: AllBrainInfo): """ Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Dictionary of...
[ "def", "process_experiences", "(", "self", ",", "current_info", ":", "AllBrainInfo", ",", "new_info", ":", "AllBrainInfo", ")", ":", "self", ".", "trainer_metrics", ".", "start_experience_collection_timer", "(", ")", "info", "=", "new_info", "[", "self", ".", "b...
Checks agent histories for processing condition, and processes them as necessary. Processing involves calculating value and advantage targets for model updating step. :param current_info: Dictionary of all current brains and corresponding BrainInfo. :param new_info: Dictionary of all next brains...
[ "Checks", "agent", "histories", "for", "processing", "condition", "and", "processes", "them", "as", "necessary", ".", "Processing", "involves", "calculating", "value", "and", "advantage", "targets", "for", "model", "updating", "step", ".", ":", "param", "current_i...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/trainer.py#L237-L291
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/trainer.py
PPOTrainer.end_episode
def end_episode(self): """ A signal that the Episode has ended. The buffer must be reset. Get only called when the academy resets. """ self.training_buffer.reset_local_buffers() for agent_id in self.cumulative_rewards: self.cumulative_rewards[agent_id] = 0 ...
python
def end_episode(self): """ A signal that the Episode has ended. The buffer must be reset. Get only called when the academy resets. """ self.training_buffer.reset_local_buffers() for agent_id in self.cumulative_rewards: self.cumulative_rewards[agent_id] = 0 ...
[ "def", "end_episode", "(", "self", ")", ":", "self", ".", "training_buffer", ".", "reset_local_buffers", "(", ")", "for", "agent_id", "in", "self", ".", "cumulative_rewards", ":", "self", ".", "cumulative_rewards", "[", "agent_id", "]", "=", "0", "for", "age...
A signal that the Episode has ended. The buffer must be reset. Get only called when the academy resets.
[ "A", "signal", "that", "the", "Episode", "has", "ended", ".", "The", "buffer", "must", "be", "reset", ".", "Get", "only", "called", "when", "the", "academy", "resets", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/trainer.py#L293-L305
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/trainer.py
PPOTrainer.is_ready_update
def is_ready_update(self): """ Returns whether or not the trainer has enough elements to run update model :return: A boolean corresponding to whether or not update_model() can be run """ size_of_buffer = len(self.training_buffer.update_buffer['actions']) return size_of_bu...
python
def is_ready_update(self): """ Returns whether or not the trainer has enough elements to run update model :return: A boolean corresponding to whether or not update_model() can be run """ size_of_buffer = len(self.training_buffer.update_buffer['actions']) return size_of_bu...
[ "def", "is_ready_update", "(", "self", ")", ":", "size_of_buffer", "=", "len", "(", "self", ".", "training_buffer", ".", "update_buffer", "[", "'actions'", "]", ")", "return", "size_of_buffer", ">", "max", "(", "int", "(", "self", ".", "trainer_parameters", ...
Returns whether or not the trainer has enough elements to run update model :return: A boolean corresponding to whether or not update_model() can be run
[ "Returns", "whether", "or", "not", "the", "trainer", "has", "enough", "elements", "to", "run", "update", "model", ":", "return", ":", "A", "boolean", "corresponding", "to", "whether", "or", "not", "update_model", "()", "can", "be", "run" ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/trainer.py#L307-L313
train
Unity-Technologies/ml-agents
ml-agents/mlagents/trainers/ppo/trainer.py
PPOTrainer.update_policy
def update_policy(self): """ Uses demonstration_buffer to update the policy. """ self.trainer_metrics.start_policy_update_timer( number_experiences=len(self.training_buffer.update_buffer['actions']), mean_return=float(np.mean(self.cumulative_returns_since_policy_u...
python
def update_policy(self): """ Uses demonstration_buffer to update the policy. """ self.trainer_metrics.start_policy_update_timer( number_experiences=len(self.training_buffer.update_buffer['actions']), mean_return=float(np.mean(self.cumulative_returns_since_policy_u...
[ "def", "update_policy", "(", "self", ")", ":", "self", ".", "trainer_metrics", ".", "start_policy_update_timer", "(", "number_experiences", "=", "len", "(", "self", ".", "training_buffer", ".", "update_buffer", "[", "'actions'", "]", ")", ",", "mean_return", "="...
Uses demonstration_buffer to update the policy.
[ "Uses", "demonstration_buffer", "to", "update", "the", "policy", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents/mlagents/trainers/ppo/trainer.py#L315-L346
train
Unity-Technologies/ml-agents
gym-unity/gym_unity/envs/unity_env.py
UnityEnv.reset
def reset(self): """Resets the state of the environment and returns an initial observation. In the case of multi-agent environments, this is a list. Returns: observation (object/list): the initial observation of the space. """ info = self._env.reset()[self.brain_name]...
python
def reset(self): """Resets the state of the environment and returns an initial observation. In the case of multi-agent environments, this is a list. Returns: observation (object/list): the initial observation of the space. """ info = self._env.reset()[self.brain_name]...
[ "def", "reset", "(", "self", ")", ":", "info", "=", "self", ".", "_env", ".", "reset", "(", ")", "[", "self", ".", "brain_name", "]", "n_agents", "=", "len", "(", "info", ".", "agents", ")", "self", ".", "_check_agents", "(", "n_agents", ")", "self...
Resets the state of the environment and returns an initial observation. In the case of multi-agent environments, this is a list. Returns: observation (object/list): the initial observation of the space.
[ "Resets", "the", "state", "of", "the", "environment", "and", "returns", "an", "initial", "observation", ".", "In", "the", "case", "of", "multi", "-", "agent", "environments", "this", "is", "a", "list", ".", "Returns", ":", "observation", "(", "object", "/"...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/gym-unity/gym_unity/envs/unity_env.py#L109-L124
train
Unity-Technologies/ml-agents
gym-unity/gym_unity/envs/unity_env.py
UnityEnv.step
def step(self, action): """Run one timestep of the environment's dynamics. When end of episode is reached, you are responsible for calling `reset()` to reset this environment's state. Accepts an action and returns a tuple (observation, reward, done, info). In the case of multi-ag...
python
def step(self, action): """Run one timestep of the environment's dynamics. When end of episode is reached, you are responsible for calling `reset()` to reset this environment's state. Accepts an action and returns a tuple (observation, reward, done, info). In the case of multi-ag...
[ "def", "step", "(", "self", ",", "action", ")", ":", "# Use random actions for all other agents in environment.", "if", "self", ".", "_multiagent", ":", "if", "not", "isinstance", "(", "action", ",", "list", ")", ":", "raise", "UnityGymException", "(", "\"The envi...
Run one timestep of the environment's dynamics. When end of episode is reached, you are responsible for calling `reset()` to reset this environment's state. Accepts an action and returns a tuple (observation, reward, done, info). In the case of multi-agent environments, these are lists. ...
[ "Run", "one", "timestep", "of", "the", "environment", "s", "dynamics", ".", "When", "end", "of", "episode", "is", "reached", "you", "are", "responsible", "for", "calling", "reset", "()", "to", "reset", "this", "environment", "s", "state", ".", "Accepts", "...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/gym-unity/gym_unity/envs/unity_env.py#L126-L169
train
Unity-Technologies/ml-agents
gym-unity/gym_unity/envs/unity_env.py
ActionFlattener._create_lookup
def _create_lookup(self, branched_action_space): """ Creates a Dict that maps discrete actions (scalars) to branched actions (lists). Each key in the Dict maps to one unique set of branched actions, and each value contains the List of branched actions. """ possible_vals =...
python
def _create_lookup(self, branched_action_space): """ Creates a Dict that maps discrete actions (scalars) to branched actions (lists). Each key in the Dict maps to one unique set of branched actions, and each value contains the List of branched actions. """ possible_vals =...
[ "def", "_create_lookup", "(", "self", ",", "branched_action_space", ")", ":", "possible_vals", "=", "[", "range", "(", "_num", ")", "for", "_num", "in", "branched_action_space", "]", "all_actions", "=", "[", "list", "(", "_action", ")", "for", "_action", "in...
Creates a Dict that maps discrete actions (scalars) to branched actions (lists). Each key in the Dict maps to one unique set of branched actions, and each value contains the List of branched actions.
[ "Creates", "a", "Dict", "that", "maps", "discrete", "actions", "(", "scalars", ")", "to", "branched", "actions", "(", "lists", ")", ".", "Each", "key", "in", "the", "Dict", "maps", "to", "one", "unique", "set", "of", "branched", "actions", "and", "each",...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/gym-unity/gym_unity/envs/unity_env.py#L279-L289
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/rpc_communicator.py
RpcCommunicator.create_server
def create_server(self): """ Creates the GRPC server. """ self.check_port(self.port) try: # Establish communication grpc self.server = grpc.server(ThreadPoolExecutor(max_workers=10)) self.unity_to_external = UnityToExternalServicerImplementati...
python
def create_server(self): """ Creates the GRPC server. """ self.check_port(self.port) try: # Establish communication grpc self.server = grpc.server(ThreadPoolExecutor(max_workers=10)) self.unity_to_external = UnityToExternalServicerImplementati...
[ "def", "create_server", "(", "self", ")", ":", "self", ".", "check_port", "(", "self", ".", "port", ")", "try", ":", "# Establish communication grpc", "self", ".", "server", "=", "grpc", ".", "server", "(", "ThreadPoolExecutor", "(", "max_workers", "=", "10"...
Creates the GRPC server.
[ "Creates", "the", "GRPC", "server", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/rpc_communicator.py#L46-L63
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/rpc_communicator.py
RpcCommunicator.check_port
def check_port(self, port): """ Attempts to bind to the requested communicator port, checking if it is already in use. """ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.bind(("localhost", port)) except socket.error: raise UnityWorker...
python
def check_port(self, port): """ Attempts to bind to the requested communicator port, checking if it is already in use. """ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.bind(("localhost", port)) except socket.error: raise UnityWorker...
[ "def", "check_port", "(", "self", ",", "port", ")", ":", "s", "=", "socket", ".", "socket", "(", "socket", ".", "AF_INET", ",", "socket", ".", "SOCK_STREAM", ")", "try", ":", "s", ".", "bind", "(", "(", "\"localhost\"", ",", "port", ")", ")", "exce...
Attempts to bind to the requested communicator port, checking if it is already in use.
[ "Attempts", "to", "bind", "to", "the", "requested", "communicator", "port", "checking", "if", "it", "is", "already", "in", "use", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/rpc_communicator.py#L65-L75
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/rpc_communicator.py
RpcCommunicator.close
def close(self): """ Sends a shutdown signal to the unity environment, and closes the grpc connection. """ if self.is_open: message_input = UnityMessage() message_input.header.status = 400 self.unity_to_external.parent_conn.send(message_input) ...
python
def close(self): """ Sends a shutdown signal to the unity environment, and closes the grpc connection. """ if self.is_open: message_input = UnityMessage() message_input.header.status = 400 self.unity_to_external.parent_conn.send(message_input) ...
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "is_open", ":", "message_input", "=", "UnityMessage", "(", ")", "message_input", ".", "header", ".", "status", "=", "400", "self", ".", "unity_to_external", ".", "parent_conn", ".", "send", "(", "...
Sends a shutdown signal to the unity environment, and closes the grpc connection.
[ "Sends", "a", "shutdown", "signal", "to", "the", "unity", "environment", "and", "closes", "the", "grpc", "connection", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/rpc_communicator.py#L103-L113
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/brain.py
BrainInfo.process_pixels
def process_pixels(image_bytes, gray_scale): """ Converts byte array observation image into numpy array, re-sizes it, and optionally converts it to grey scale :param gray_scale: Whether to convert the image to grayscale. :param image_bytes: input byte array corresponding to image...
python
def process_pixels(image_bytes, gray_scale): """ Converts byte array observation image into numpy array, re-sizes it, and optionally converts it to grey scale :param gray_scale: Whether to convert the image to grayscale. :param image_bytes: input byte array corresponding to image...
[ "def", "process_pixels", "(", "image_bytes", ",", "gray_scale", ")", ":", "s", "=", "bytearray", "(", "image_bytes", ")", "image", "=", "Image", ".", "open", "(", "io", ".", "BytesIO", "(", "s", ")", ")", "s", "=", "np", ".", "array", "(", "image", ...
Converts byte array observation image into numpy array, re-sizes it, and optionally converts it to grey scale :param gray_scale: Whether to convert the image to grayscale. :param image_bytes: input byte array corresponding to image :return: processed numpy array of observation from envir...
[ "Converts", "byte", "array", "observation", "image", "into", "numpy", "array", "re", "-", "sizes", "it", "and", "optionally", "converts", "it", "to", "grey", "scale", ":", "param", "gray_scale", ":", "Whether", "to", "convert", "the", "image", "to", "graysca...
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/brain.py#L68-L82
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/brain.py
BrainInfo.from_agent_proto
def from_agent_proto(agent_info_list, brain_params): """ Converts list of agent infos to BrainInfo. """ vis_obs = [] for i in range(brain_params.number_visual_observations): obs = [BrainInfo.process_pixels(x.visual_observations[i], ...
python
def from_agent_proto(agent_info_list, brain_params): """ Converts list of agent infos to BrainInfo. """ vis_obs = [] for i in range(brain_params.number_visual_observations): obs = [BrainInfo.process_pixels(x.visual_observations[i], ...
[ "def", "from_agent_proto", "(", "agent_info_list", ",", "brain_params", ")", ":", "vis_obs", "=", "[", "]", "for", "i", "in", "range", "(", "brain_params", ".", "number_visual_observations", ")", ":", "obs", "=", "[", "BrainInfo", ".", "process_pixels", "(", ...
Converts list of agent infos to BrainInfo.
[ "Converts", "list", "of", "agent", "infos", "to", "BrainInfo", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/brain.py#L85-L138
train
Unity-Technologies/ml-agents
ml-agents-envs/mlagents/envs/brain.py
BrainParameters.from_proto
def from_proto(brain_param_proto): """ Converts brain parameter proto to BrainParameter object. :param brain_param_proto: protobuf object. :return: BrainParameter object. """ resolution = [{ "height": x.height, "width": x.width, "blackA...
python
def from_proto(brain_param_proto): """ Converts brain parameter proto to BrainParameter object. :param brain_param_proto: protobuf object. :return: BrainParameter object. """ resolution = [{ "height": x.height, "width": x.width, "blackA...
[ "def", "from_proto", "(", "brain_param_proto", ")", ":", "resolution", "=", "[", "{", "\"height\"", ":", "x", ".", "height", ",", "\"width\"", ":", "x", ".", "width", ",", "\"blackAndWhite\"", ":", "x", ".", "gray_scale", "}", "for", "x", "in", "brain_pa...
Converts brain parameter proto to BrainParameter object. :param brain_param_proto: protobuf object. :return: BrainParameter object.
[ "Converts", "brain", "parameter", "proto", "to", "BrainParameter", "object", ".", ":", "param", "brain_param_proto", ":", "protobuf", "object", ".", ":", "return", ":", "BrainParameter", "object", "." ]
37d139af636e4a2351751fbf0f2fca5a9ed7457f
https://github.com/Unity-Technologies/ml-agents/blob/37d139af636e4a2351751fbf0f2fca5a9ed7457f/ml-agents-envs/mlagents/envs/brain.py#L206-L224
train
apache/incubator-superset
superset/views/dashboard.py
Dashboard.new
def new(self): """Creates a new, blank dashboard and redirects to it in edit mode""" new_dashboard = models.Dashboard( dashboard_title='[ untitled dashboard ]', owners=[g.user], ) db.session.add(new_dashboard) db.session.commit() return redirect(f'...
python
def new(self): """Creates a new, blank dashboard and redirects to it in edit mode""" new_dashboard = models.Dashboard( dashboard_title='[ untitled dashboard ]', owners=[g.user], ) db.session.add(new_dashboard) db.session.commit() return redirect(f'...
[ "def", "new", "(", "self", ")", ":", "new_dashboard", "=", "models", ".", "Dashboard", "(", "dashboard_title", "=", "'[ untitled dashboard ]'", ",", "owners", "=", "[", "g", ".", "user", "]", ",", ")", "db", ".", "session", ".", "add", "(", "new_dashboar...
Creates a new, blank dashboard and redirects to it in edit mode
[ "Creates", "a", "new", "blank", "dashboard", "and", "redirects", "to", "it", "in", "edit", "mode" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/views/dashboard.py#L32-L40
train
apache/incubator-superset
superset/views/tags.py
TagView.get
def get(self, object_type, object_id): """List all tags a given object has.""" if object_id == 0: return json_success(json.dumps([])) query = db.session.query(TaggedObject).filter(and_( TaggedObject.object_type == object_type, TaggedObject.object_id == object...
python
def get(self, object_type, object_id): """List all tags a given object has.""" if object_id == 0: return json_success(json.dumps([])) query = db.session.query(TaggedObject).filter(and_( TaggedObject.object_type == object_type, TaggedObject.object_id == object...
[ "def", "get", "(", "self", ",", "object_type", ",", "object_id", ")", ":", "if", "object_id", "==", "0", ":", "return", "json_success", "(", "json", ".", "dumps", "(", "[", "]", ")", ")", "query", "=", "db", ".", "session", ".", "query", "(", "Tagg...
List all tags a given object has.
[ "List", "all", "tags", "a", "given", "object", "has", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/views/tags.py#L78-L87
train
apache/incubator-superset
superset/views/tags.py
TagView.post
def post(self, object_type, object_id): """Add new tags to an object.""" if object_id == 0: return Response(status=404) tagged_objects = [] for name in request.get_json(force=True): if ':' in name: type_name = name.split(':', 1)[0] ...
python
def post(self, object_type, object_id): """Add new tags to an object.""" if object_id == 0: return Response(status=404) tagged_objects = [] for name in request.get_json(force=True): if ':' in name: type_name = name.split(':', 1)[0] ...
[ "def", "post", "(", "self", ",", "object_type", ",", "object_id", ")", ":", "if", "object_id", "==", "0", ":", "return", "Response", "(", "status", "=", "404", ")", "tagged_objects", "=", "[", "]", "for", "name", "in", "request", ".", "get_json", "(", ...
Add new tags to an object.
[ "Add", "new", "tags", "to", "an", "object", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/views/tags.py#L91-L119
train
apache/incubator-superset
superset/views/tags.py
TagView.delete
def delete(self, object_type, object_id): """Remove tags from an object.""" tag_names = request.get_json(force=True) if not tag_names: return Response(status=403) db.session.query(TaggedObject).filter(and_( TaggedObject.object_type == object_type, Tag...
python
def delete(self, object_type, object_id): """Remove tags from an object.""" tag_names = request.get_json(force=True) if not tag_names: return Response(status=403) db.session.query(TaggedObject).filter(and_( TaggedObject.object_type == object_type, Tag...
[ "def", "delete", "(", "self", ",", "object_type", ",", "object_id", ")", ":", "tag_names", "=", "request", ".", "get_json", "(", "force", "=", "True", ")", "if", "not", "tag_names", ":", "return", "Response", "(", "status", "=", "403", ")", "db", ".", ...
Remove tags from an object.
[ "Remove", "tags", "from", "an", "object", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/views/tags.py#L123-L136
train
apache/incubator-superset
superset/utils/import_datasource.py
import_datasource
def import_datasource( session, i_datasource, lookup_database, lookup_datasource, import_time): """Imports the datasource from the object to the database. Metrics and columns and datasource will be overrided if exists. This function can be used to import/export das...
python
def import_datasource( session, i_datasource, lookup_database, lookup_datasource, import_time): """Imports the datasource from the object to the database. Metrics and columns and datasource will be overrided if exists. This function can be used to import/export das...
[ "def", "import_datasource", "(", "session", ",", "i_datasource", ",", "lookup_database", ",", "lookup_datasource", ",", "import_time", ")", ":", "make_transient", "(", "i_datasource", ")", "logging", ".", "info", "(", "'Started import of the datasource: {}'", ".", "fo...
Imports the datasource from the object to the database. Metrics and columns and datasource will be overrided if exists. This function can be used to import/export dashboards between multiple superset instances. Audit metadata isn't copies over.
[ "Imports", "the", "datasource", "from", "the", "object", "to", "the", "database", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/import_datasource.py#L23-L74
train
apache/incubator-superset
superset/migrations/env.py
run_migrations_online
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: h...
python
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ # this callback is used to prevent an auto-migration from being generated # when there are no changes to the schema # reference: h...
[ "def", "run_migrations_online", "(", ")", ":", "# this callback is used to prevent an auto-migration from being generated", "# when there are no changes to the schema", "# reference: https://alembic.sqlalchemy.org/en/latest/cookbook.html", "def", "process_revision_directives", "(", "context", ...
Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context.
[ "Run", "migrations", "in", "online", "mode", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/migrations/env.py#L68-L111
train
apache/incubator-superset
superset/viz.py
BaseViz.get_df
def get_df(self, query_obj=None): """Returns a pandas dataframe based on the query object""" if not query_obj: query_obj = self.query_obj() if not query_obj: return None self.error_msg = '' timestamp_format = None if self.datasource.type == 'tabl...
python
def get_df(self, query_obj=None): """Returns a pandas dataframe based on the query object""" if not query_obj: query_obj = self.query_obj() if not query_obj: return None self.error_msg = '' timestamp_format = None if self.datasource.type == 'tabl...
[ "def", "get_df", "(", "self", ",", "query_obj", "=", "None", ")", ":", "if", "not", "query_obj", ":", "query_obj", "=", "self", ".", "query_obj", "(", ")", "if", "not", "query_obj", ":", "return", "None", "self", ".", "error_msg", "=", "''", "timestamp...
Returns a pandas dataframe based on the query object
[ "Returns", "a", "pandas", "dataframe", "based", "on", "the", "query", "object" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/viz.py#L177-L235
train
apache/incubator-superset
superset/viz.py
BaseViz.query_obj
def query_obj(self): """Building a query object""" form_data = self.form_data self.process_query_filters() gb = form_data.get('groupby') or [] metrics = self.all_metrics or [] columns = form_data.get('columns') or [] groupby = [] for o in gb + columns: ...
python
def query_obj(self): """Building a query object""" form_data = self.form_data self.process_query_filters() gb = form_data.get('groupby') or [] metrics = self.all_metrics or [] columns = form_data.get('columns') or [] groupby = [] for o in gb + columns: ...
[ "def", "query_obj", "(", "self", ")", ":", "form_data", "=", "self", ".", "form_data", "self", ".", "process_query_filters", "(", ")", "gb", "=", "form_data", ".", "get", "(", "'groupby'", ")", "or", "[", "]", "metrics", "=", "self", ".", "all_metrics", ...
Building a query object
[ "Building", "a", "query", "object" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/viz.py#L249-L317
train
apache/incubator-superset
superset/viz.py
BaseViz.cache_key
def cache_key(self, query_obj, **extra): """ The cache key is made out of the key/values in `query_obj`, plus any other key/values in `extra`. We remove datetime bounds that are hard values, and replace them with the use-provided inputs to bounds, which may be time-relative (as ...
python
def cache_key(self, query_obj, **extra): """ The cache key is made out of the key/values in `query_obj`, plus any other key/values in `extra`. We remove datetime bounds that are hard values, and replace them with the use-provided inputs to bounds, which may be time-relative (as ...
[ "def", "cache_key", "(", "self", ",", "query_obj", ",", "*", "*", "extra", ")", ":", "cache_dict", "=", "copy", ".", "copy", "(", "query_obj", ")", "cache_dict", ".", "update", "(", "extra", ")", "for", "k", "in", "[", "'from_dttm'", ",", "'to_dttm'", ...
The cache key is made out of the key/values in `query_obj`, plus any other key/values in `extra`. We remove datetime bounds that are hard values, and replace them with the use-provided inputs to bounds, which may be time-relative (as in "5 days ago" or "now"). The `extra` argum...
[ "The", "cache", "key", "is", "made", "out", "of", "the", "key", "/", "values", "in", "query_obj", "plus", "any", "other", "key", "/", "values", "in", "extra", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/viz.py#L336-L358
train
apache/incubator-superset
superset/viz.py
BaseViz.data
def data(self): """This is the data object serialized to the js layer""" content = { 'form_data': self.form_data, 'token': self.token, 'viz_name': self.viz_type, 'filter_select_enabled': self.datasource.filter_select_enabled, } return conte...
python
def data(self): """This is the data object serialized to the js layer""" content = { 'form_data': self.form_data, 'token': self.token, 'viz_name': self.viz_type, 'filter_select_enabled': self.datasource.filter_select_enabled, } return conte...
[ "def", "data", "(", "self", ")", ":", "content", "=", "{", "'form_data'", ":", "self", ".", "form_data", ",", "'token'", ":", "self", ".", "token", ",", "'viz_name'", ":", "self", ".", "viz_type", ",", "'filter_select_enabled'", ":", "self", ".", "dataso...
This is the data object serialized to the js layer
[ "This", "is", "the", "data", "object", "serialized", "to", "the", "js", "layer" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/viz.py#L472-L480
train
apache/incubator-superset
superset/viz.py
HistogramViz.query_obj
def query_obj(self): """Returns the query object for this visualization""" d = super().query_obj() d['row_limit'] = self.form_data.get( 'row_limit', int(config.get('VIZ_ROW_LIMIT'))) numeric_columns = self.form_data.get('all_columns_x') if numeric_columns is None: ...
python
def query_obj(self): """Returns the query object for this visualization""" d = super().query_obj() d['row_limit'] = self.form_data.get( 'row_limit', int(config.get('VIZ_ROW_LIMIT'))) numeric_columns = self.form_data.get('all_columns_x') if numeric_columns is None: ...
[ "def", "query_obj", "(", "self", ")", ":", "d", "=", "super", "(", ")", ".", "query_obj", "(", ")", "d", "[", "'row_limit'", "]", "=", "self", ".", "form_data", ".", "get", "(", "'row_limit'", ",", "int", "(", "config", ".", "get", "(", "'VIZ_ROW_L...
Returns the query object for this visualization
[ "Returns", "the", "query", "object", "for", "this", "visualization" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/viz.py#L1474-L1486
train
apache/incubator-superset
superset/viz.py
HistogramViz.get_data
def get_data(self, df): """Returns the chart data""" chart_data = [] if len(self.groupby) > 0: groups = df.groupby(self.groupby) else: groups = [((), df)] for keys, data in groups: chart_data.extend([{ 'key': self.labelify(keys,...
python
def get_data(self, df): """Returns the chart data""" chart_data = [] if len(self.groupby) > 0: groups = df.groupby(self.groupby) else: groups = [((), df)] for keys, data in groups: chart_data.extend([{ 'key': self.labelify(keys,...
[ "def", "get_data", "(", "self", ",", "df", ")", ":", "chart_data", "=", "[", "]", "if", "len", "(", "self", ".", "groupby", ")", ">", "0", ":", "groups", "=", "df", ".", "groupby", "(", "self", ".", "groupby", ")", "else", ":", "groups", "=", "...
Returns the chart data
[ "Returns", "the", "chart", "data" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/viz.py#L1498-L1510
train