def add_objective(self, name, maximize, tag, node_func=None, output_node_name=None, logging_only=False): """Add an optimization objective to the dictionary. Objectives must be added in order of importance, however fitness is fixed to be the most important. The keys of an ObjectiveDict correspond to the objective's rank or importance. The ranks are set via the order in which objectives are added (fitness will auto-correct to rank 0). For each rank key, starting with 0, the corresponding value is another dictionary with three components: name, maximized, tag. Parameters ---------- name : str The associated individual-level attribute name maximize : bool Whether superior individuals maximized (True) or minimize (False) the objective. tag : str or None The tag used in parsing the resulting output from a VoxCad simulation. If this is None then the attribute is calculated outside of VoxCad (in Python only). node_func : function If tag is None then the objective is not computed in VoxCad and is instead calculated on an output of a network. output_node_name : str The output node which node_func operates on. logging_only : bool If True then don't use as objective, only to track statistics from the simulation. """ curr_rank = self.max_rank # if fitness is not added first, shift every other objective "down" in importance if name == "fitness" and self.max_rank > 0: curr_rank = 0 # change the key to rank 0 for rank in reversed(range(len(self))): self[rank + 1] = self[rank] super(ObjectiveDict, self).__setitem__( curr_rank, { "name": name, "maximize": maximize, "tag": xml_format(tag) if tag is not None else None, "worst_value": -10e6 if maximize else 10e6, #"worst_value": 0, "node_func": node_func, "output_node_name": output_node_name, "logging_only": logging_only }) # TODO: logging_only 'objectives' should be a separate 'SimStats' class self.max_rank += 1
def add_map(self, name, tag, func=sigmoid, output_type=float, dependency_order=None, params=None, param_tags=None, env_kws=None, logging_stats=np.mean): """Add an association between a genotype output and a VoxCad parameter. Parameters ---------- name : str A network output node name from the genotype. tag : str The tag used in parsing the resulting output from a VoxCad simulation. If this is None then the attribute is calculated outside of VoxCad (in Python only). func : func Specifies relationship between attributes and xml tag. output_type : type The output type dependency_order : list Order of operations params : list Constants dictating parameters of the mapping param_tags : list Tags for any constants associated with the mapping env_kws : dict Specifies which function of the output state to use (on top of func) to set an Env attribute logging_stats : func or list One or more functions (statistics) of the output to be logged as additional column(s) in logging """ if (dependency_order is not None) and not isinstance(dependency_order, list): dependency_order = [dependency_order] if params is not None: assert (param_tags is not None) if not isinstance(params, list): params = [params] if param_tags is not None: assert (params is not None) if not isinstance(param_tags, list): param_tags = [param_tags] param_tags = [xml_format(t) for t in param_tags] if (env_kws is not None) and not isinstance(env_kws, dict): env_kws = {env_kws: np.mean} if (logging_stats is not None) and not isinstance(logging_stats, list): logging_stats = [logging_stats] if tag is not None: tag = xml_format(tag) self.mapping[name] = {"tag": tag, "func": func, "dependency_order": dependency_order, "state": None, "old_state": None, "output_type": output_type, "params": params, "param_tags": param_tags, "env_kws": env_kws, "logging_stats": logging_stats}
def add_param(self, name, val, tag): setattr(self, name, val) self.new_param_tag_dict[name] = xml_format(tag)
def add_map(self, name, tag, func=sigmoid, output_type=float, dependency_order=None, params=None, param_tags=None, env_kws=None, logging_stats=np.mean, age_zero_overwrite=None, switch_proportion=0, switch_name=None): """Add an association between a genotype output and a VoxCad parameter. Parameters ---------- name : str A network output node name from the genotype. tag : str The tag used in parsing the resulting output from a VoxCad simulation. If this is None then the attribute is calculated outside of VoxCad (in Python only). func : func Specifies relationship between attributes and xml tag. output_type : type The output type dependency_order : list Order of operations params : list Constants dictating parameters of the mapping param_tags : list Tags for any constants associated with the mapping env_kws : dict Specifies which function of the output state to use (on top of func) to set an Env attribute logging_stats : func or list One or more functions (statistics) of the output to be logged as additional column(s) in logging age_zero_overwrite : str Evaluate this network with this placeholder at birth (age=0) instead of actual values. switch_proportion : float Switches are non-inheritable portions of genotype (Hinton & Nowlan, 1987). switch_name : str Network name containing switch values """ if (dependency_order is not None) and not isinstance(dependency_order, list): dependency_order = [dependency_order] if params is not None: assert (param_tags is not None) if not isinstance(params, list): params = [params] if param_tags is not None: assert (params is not None) if not isinstance(param_tags, list): param_tags = [param_tags] param_tags = [xml_format(t) for t in param_tags] if (env_kws is not None) and not isinstance(env_kws, dict): env_kws = {env_kws: np.mean} if (logging_stats is not None) and not isinstance(logging_stats, list): logging_stats = [logging_stats] if tag is not None: tag = xml_format(tag) self.mapping[name] = {"tag": tag, "func": func, "dependency_order": dependency_order, "state": None, "oldstate": None, #daniel: was old_state before "output_type": output_type, "params": params, "param_tags": param_tags, "env_kws": env_kws, "logging_stats": logging_stats, "age_zero_overwrite": age_zero_overwrite, "switch_proportion": switch_proportion, "switch_name": switch_name}