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
评论列表
文章目录