All function with state will update the state and return it.
Remove randkey args in functions with state, since it can attach the randkey by states.
This commit is contained in:
@@ -3,8 +3,8 @@ from utils import State
|
||||
|
||||
class BaseMutation:
|
||||
|
||||
def setup(self, key, state=State()):
|
||||
def setup(self, state=State()):
|
||||
return state
|
||||
|
||||
def __call__(self, state, key, genome, nodes, conns, new_node_key):
|
||||
def __call__(self, state, genome, nodes, conns, new_node_key):
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -17,13 +17,13 @@ class DefaultMutation(BaseMutation):
|
||||
self.node_add = node_add
|
||||
self.node_delete = node_delete
|
||||
|
||||
def __call__(self, state, key, genome, nodes, conns, new_node_key):
|
||||
k1, k2 = jax.random.split(key)
|
||||
def __call__(self, state, genome, nodes, conns, new_node_key):
|
||||
k1, k2, randkey = jax.random.split(state.randkey)
|
||||
|
||||
nodes, conns = self.mutate_structure(k1, genome, nodes, conns, new_node_key)
|
||||
nodes, conns = self.mutate_values(k2, genome, nodes, conns)
|
||||
|
||||
return nodes, conns
|
||||
return state.update(randkey=randkey), nodes, conns
|
||||
|
||||
def mutate_structure(self, key, genome, nodes, conns, new_node_key):
|
||||
def mutate_add_node(key_, nodes_, conns_):
|
||||
|
||||
Reference in New Issue
Block a user