binary_individual.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:gaft 作者: PytLab 项目源码 文件源码
def __init__(self, ranges, eps=0.001):
        '''
        Class for individual in population. Random solution will be initialized
        by default.

        NOTE: The decrete precisions for different components in varants may be
              adjusted automatically (possible precision loss) if eps and ranges
              are not appropriate.

        :param ranges: value ranges for all entries in solution.
        :type ranges: list of range tuples. e.g. [(0, 1), (-1, 1)]

        :param eps: decrete precisions for binary encoding, default is 0.001.
        :type eps: float or float list with the same length with ranges.
        '''
        super(self.__class__, self).__init__(ranges, eps)

        # Lengths for all binary sequence in chromsome and adjusted decrete precisions.
        self.lengths = []

        for i, ((a, b), eps) in enumerate(zip(self.ranges, self.eps)):
            length = int(log2((b - a)/eps))
            precision = (b - a)/(2**length)
            self.lengths.append(length)
            self.precisions[i] = precision

        # The start and end indices for each gene segment for entries in solution.
        self.gene_indices = self._get_gene_indices()

        # Initialize individual randomly.
        self.init()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号