当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.parameter_keys方法代码示例

本文整理汇总了Python中configuration.Configuration.parameter_keys方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.parameter_keys方法的具体用法?Python Configuration.parameter_keys怎么用?Python Configuration.parameter_keys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在configuration.Configuration的用法示例。


在下文中一共展示了Configuration.parameter_keys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: reset

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import parameter_keys [as 别名]
    def reset(self):
        print "[Genetic Search]\n-> Initializing population of size: %s" % self.__pop_size
        self.__pop = []
        # vector of still unused parameters
        # this is done to avoid to have some of the parameters out of the first population
        unused_params = [param for param in self.__config.parameters.values()]
        ratio = int(math.ceil(float(len(self.__config)) / float(self.__pop_size)))

        while len(self.__pop) < self.__pop_size:
            # the gene length for this individual will be chosen randomly between 2 and n
            length = random.randint(1, len(self.__config))
            element = Configuration()

            for gene in range(length):
                if gene < ratio and len(unused_params) != 0:
                    idx = random.randint(0, len(unused_params) - 1)
                    param = unused_params[idx]
                    param.rand()
                    element += param
                    del unused_params[idx]
                    continue
                # we choose each gene randomly
                param = None
                while param is None:
                    idx = random.randint(0, len(self.__config) - 1)
                    param = self.__config.parameters.values()[idx]
                    if not param in element.parameters.values():
                        param.rand()
                        element += param
                    else:
                        param = None

                # remove from the list of mandatory params
                if param in unused_params:
                    unused_params.remove(param)

            added_params = []
            for param in self.__config.parameters.values():
                if param.name not in element.parameter_keys():
                    element += param
                    added_params.append(param)

            if element.check(self.__constraints):
                self.__pop.append(element)

            for param in added_params:
                element -= param
开发者ID:motonacciu,项目名称:BenchRunner,代码行数:49,代码来源:iterator.py

示例2: crossover

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import parameter_keys [as 别名]
    def crossover(self, p1, p2):
        offsprings = []
        # Crossover
        for offspring_idx in range(2):
            # decide the size of the offspring
            offspring = Configuration()

            lb = min(len(p1), len(p2))
            ub = max(len(p1), len(p2))

            # we choose the size randomly between the 2 parents' size
            size = random.randint(lb, ub)

            common = set()
            for p1_gene in p1.parameters.values():
                if p1_gene in p2.parameters.values():
                    # two parents have the same gene
                    if random.randint(0, 1):
                        offspring += p1_gene
                    else:
                        offspring += p2.parameters[p1_gene.name]
                    common.add(p1_gene)

            # print ','.join(map(lambda x: x.name, common))
            remaining = list((set(p1.parameters.values()) - common) | (set(p2.parameters.values()) - common))
            # print ','.join(map(lambda x: x.name, remaining))

            while len(offspring) < size:
                # select from the remaining genes
                idx = random.randint(0, len(remaining) - 1)
                if remaining[idx].name not in offspring.parameter_keys():
                    offspring += remaining[idx]
                    del remaining[idx]

            offsprings.append(offspring)

        return tuple(offsprings)
开发者ID:motonacciu,项目名称:BenchRunner,代码行数:39,代码来源:iterator.py


注:本文中的configuration.Configuration.parameter_keys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。