generally complete, but not work well. Debug
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from .genome import create_initialize_function
|
||||
from .genome import create_initialize_function, expand, expand_single
|
||||
from .distance import distance
|
||||
from .mutate import create_mutate_function
|
||||
from .forward import create_forward_function
|
||||
from .crossover import batch_crossover
|
||||
|
||||
@@ -99,8 +99,8 @@ def initialize_genomes(pop_size: int,
|
||||
def expand(pop_nodes: NDArray, pop_connections: NDArray, new_N: int) -> Tuple[NDArray, NDArray]:
|
||||
"""
|
||||
Expand the genome to accommodate more nodes.
|
||||
:param pop_nodes:
|
||||
:param pop_connections:
|
||||
:param pop_nodes: (pop_size, N, 5)
|
||||
:param pop_connections: (pop_size, 2, N, N)
|
||||
:param new_N:
|
||||
:return:
|
||||
"""
|
||||
@@ -114,6 +114,23 @@ def expand(pop_nodes: NDArray, pop_connections: NDArray, new_N: int) -> Tuple[ND
|
||||
return new_pop_nodes, new_pop_connections
|
||||
|
||||
|
||||
def expand_single(nodes: NDArray, connections: NDArray, new_N: int) -> Tuple[NDArray, NDArray]:
|
||||
"""
|
||||
Expand a single genome to accommodate more nodes.
|
||||
:param nodes: (N, 5)
|
||||
:param connections: (2, N, N)
|
||||
:param new_N:
|
||||
:return:
|
||||
"""
|
||||
old_N = nodes.shape[0]
|
||||
new_nodes = np.full((new_N, 5), np.nan)
|
||||
new_nodes[:old_N, :] = nodes
|
||||
|
||||
new_connections = np.full((2, new_N, new_N), np.nan)
|
||||
new_connections[:, :old_N, :old_N] = connections
|
||||
|
||||
return new_nodes, new_connections
|
||||
|
||||
@jit
|
||||
def add_node(new_node_key: int, nodes: Array, connections: Array,
|
||||
bias: float = 0.0, response: float = 1.0, act: int = 0, agg: int = 0) -> Tuple[Array, Array]:
|
||||
|
||||
Reference in New Issue
Block a user