change a lot

This commit is contained in:
wls2002
2023-07-17 17:39:12 +08:00
parent a0a1ef6c58
commit f4763ebcea
21 changed files with 1060 additions and 4 deletions

4
examples/config_test.py Normal file
View File

@@ -0,0 +1,4 @@
from algorithm.config import Configer
config = Configer.load_config()
print(config)

View File

@@ -1,6 +1,8 @@
import jax
from jax import numpy as jnp
from algorithm.state import State
@jax.jit
def func(state: State, a):
return state.update(a=a)
@@ -9,6 +11,5 @@ def func(state: State, a):
state = State(c=1, b=2)
print(state)
state = func(state, 1111111)
print(state)
vmap_func = jax.vmap(func, in_axes=(None, 0))
print(vmap_func(state, jnp.array([1, 2, 3])))

16
examples/xor_test.py Normal file
View File

@@ -0,0 +1,16 @@
import jax
from algorithm.config import Configer
from algorithm.neat import NEAT
from algorithm.neat.genome import create_mutate
if __name__ == '__main__':
config = Configer.load_config()
neat = NEAT(config)
randkey = jax.random.PRNGKey(42)
state = neat.setup(randkey)
mutate_func = jax.jit(create_mutate(config, neat.gene_type))
state = mutate_func(state)
print(state)