analysis.py 文件源码

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

项目:CA-NEAT 作者: mathiasose 项目源码 文件源码
def calculate_dominance(cppn: FeedForwardNetwork, ca_config: CAConfig) -> float:
    alphabet = ca_config.alphabet
    neighbourhood = ca_config.neighbourhood

    nbhs = list(product(alphabet, repeat=len(neighbourhood)))
    rules = create_state_normalization_rules(states=alphabet)

    quiescent = alphabet[0]

    def transition_f(inputs_discrete_values: Sequence[CELL_STATE_T]) -> CELL_STATE_T:
        if all((x == quiescent) for x in inputs_discrete_values):
            return quiescent

        inputs_float_values = tuple(rules[x] for x in inputs_discrete_values)

        outputs = cppn.serial_activate(inputs_float_values)

        return max(zip(alphabet, outputs), key=itemgetter(1))[0]

    heterogenous, homogenous = 0, 0

    for nbh in nbhs:
        try:
            output = transition_f(nbh)
        except OverflowError:
            continue

        m = mode(nbh)

        if output != m:
            continue
        elif all(x == m for x in nbh):
            homogenous += 1
        else:
            heterogenous += 1

    return 3 * homogenous + heterogenous
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号