initial commit in branch developing

This commit is contained in:
wls2002
2023-05-11 19:04:56 +08:00
parent acc9eab64a
commit e2a5117554
41 changed files with 133 additions and 43 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,21 +1,5 @@
import jax
import jax.numpy as jnp
import numpy as np
from jax import random
from jax import vmap, jit
from functools import partial
from examples.time_utils import using_cprofile
EMPTY_NODE = jnp.full((1, 5), jnp.nan)
@jit
def func(x, y):
return x + y
a, b, c = jnp.array([1]), jnp.array([2]), jnp.array([3])
li = [a, b, c]
cpu_li = jax.device_get(li)
print(cpu_li)
print(EMPTY_NODE)

View File

@@ -6,35 +6,14 @@ from time_utils import using_cprofile
from problems import Sin, Xor, DIY
# xor_inputs = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float32)
# xor_outputs = np.array([[0], [1], [1], [0]])
#
#
# def evaluate(forward_func: Callable) -> List[float]:
# """
# :param forward_func: (4: batch, 2: input size) -> (pop_size, 4: batch, 1: output size)
# :return:
# """
# outs = forward_func(xor_inputs)
# outs = jax.device_get(outs)
# fitnesses = 4 - np.sum((outs - xor_outputs) ** 2, axis=(1, 2))
# return fitnesses.tolist() # returns a list
# @using_cprofile
@partial(using_cprofile, root_abs_path='/mnt/e/neat-jax/', replace_pattern="/mnt/e/neat-jax/")
def main():
config = Configer.load_config()
# config.neat.population.pop_size = 50
problem = Xor()
# problem = Sin()
# problem = DIY(func=lambda x: (np.sin(x) + np.exp(x) - x ** 2) / (np.cos(x) + np.sqrt(x)) - np.log(x + 1))
problem.refactor_config(config)
pipeline = Pipeline(config, seed=0)
best_nodes, best_connections = pipeline.auto_run(problem.evaluate)
# print(best_nodes, best_connections)
# func = pipeline.function_factory.ask_batch_forward(best_nodes, best_connections)
# problem.print(func)
pipeline.auto_run(problem.evaluate)
if __name__ == '__main__':