hyper neat

This commit is contained in:
wls2002
2023-07-24 19:25:02 +08:00
parent ac295c1921
commit ebad574431
24 changed files with 542 additions and 103 deletions

View File

@@ -2,4 +2,4 @@ from .algorithm import Algorithm
from .state import State
from .genome import Genome
from .gene import Gene
from .substrate import Substrate

View File

@@ -40,7 +40,7 @@ class Gene:
@staticmethod
def forward_transform(state: State, genome: Genome):
return jnp.zeros(0) # transformed
@staticmethod
def create_forward(state: State, config: GeneConfig):
return lambda *args: args # forward function

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from jax.tree_util import register_pytree_node_class
from jax import numpy as jnp
@@ -11,6 +13,15 @@ class Genome:
self.nodes = nodes
self.conns = conns
def __repr__(self):
return f"Genome(nodes={self.nodes}, conns={self.conns})"
def __getitem__(self, idx):
return self.__class__(self.nodes[idx], self.conns[idx])
def set(self, idx, value: Genome):
return self.__class__(self.nodes.at[idx].set(value.nodes), self.conns.at[idx].set(value.conns))
def update(self, nodes, conns):
return self.__class__(nodes, conns)
@@ -73,5 +84,4 @@ class Genome:
def tree_unflatten(cls, aux_data, children):
return cls(*children)
def __repr__(self):
return f"Genome(nodes={self.nodes}, conns={self.conns})"

8
core/substrate.py Normal file
View File

@@ -0,0 +1,8 @@
from config import SubstrateConfig
class Substrate:
@staticmethod
def setup(state, config: SubstrateConfig):
return state